Olá pessoal…
Não estou conseguindo definir o datasource(Mysql) pelo tomcat 7…quem puder ajudar agredeço desde já
Eis o meu Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>First</display-name>
//servlet, etc
<resource-ref>
<res-ref-name>jdbc/banco</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Meu context.xml
<Context>
<Resource
name="jdbc/banco"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="minhasenha"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/jsf" />
</Context>
Classe de conexão:
import java.sql.Connection;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.sql.DataSource;
public class Conexao{
@Resource(name="jdbc/banco")
private DataSource dataSource;
public Connection conectarMysql() throws SQLException{
if(dataSource == null){
throw new SQLException("DataSource inexistente");
}
Connection connection = dataSource.getConnection();
if(connection == null){
throw new SQLException("Não há conexão com o banco");
}
return connection;
}
}
e adicionei o mysql-connector-java-5.1.17-bin.jar na lib do tomcat…
o método conectarMysql() me retorna DataSource inexistente…
está faltando algo e/ou tem algo errado?
Valeu!