Tentei alterar uma classe que funcionava a conexão direta (exemplo 1) por outra utilizando DataSource (exemplo 2), mas apresentou erro no “conn.createStatement()” de “No suitable driver”.
Alguém sabe dizer porque?
[color=brown]Exemplo: 1
public static Connection getConnection() throws Exception
{
try
{[/color][color=red]
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection(“jdbc:mysql://localhost:3307/DevAcc?user=root&password=root”); }[/color][color=brown] catch (SQLException se)
{
throw new Exception(se);
}
return conn;
}
public ArrayList findAll() throws Exception
{
String command ;
ArrayList resultCommand = new ArrayList();
command = “select” +
" ID_PROJETO " +
" ,COD_PROJETO " +
" ,DES_TITLE " +
" ,DES_PROJETO " +
" ,DES_LOCAL " +
" ,DES_PROPERTY " +
" ,DES_BEAN " +
" ,DES_BUSINESS " +
" ,DES_DATABASE " +
" ,DES_DAO " +
" ,DES_UI " +
" ,DES_HTML " +
"from PROJETO ";
resultCommand = this.executeArray(command);
return resultCommand;
}
public ArrayList executeArray(String newComando) throws Exception
{
result = new ArrayList();
try
{
// Conecta no banco de dados
Connection conn = ConexaoMySQL.getConnection();
Statement rs = conn.createStatement();
ResultSet rset = rs.executeQuery(newComando);
this.result = this.montaArray(rset);;
// Fecha Connection e CallableStatement
ConexaoMySQL.closeConnection();
rs.close();
rset.close();
this.codErro = “0”;
return this.result;
}
catch(SQLException se)
{
this.codErro = Integer.toString(se.getErrorCode());
this.msgErro = se.getMessage();
// Fecha Connection e CallableStatement
ConexaoMySQL.closeConnection();
this.result = result;
return this.result;
}
}
=========================================
Exemplo: 2
public static Connection getConnection() throws Exception
{
try
{
[/color][color=red]DataSource ds = null;
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
InitialContext ic = new InitialContext();
ResourceBundle resource = ResourceBundle.getBundle(“Teste”);
ds = (DataSource) ic.lookup(resource.getString(“Teste.datasource”));
conn = ds.getConnection();[/color][color=brown] }
catch (SQLException se)
{
throw new Exception(se);
}
return conn;
}
public ArrayList findAll() throws Exception
{
String command ;
ArrayList resultCommand = new ArrayList();
command = “select” +
" ID_PROJETO " +
" ,COD_PROJETO " +
" ,DES_TITLE " +
" ,DES_PROJETO " +
" ,DES_LOCAL " +
" ,DES_PROPERTY " +
" ,DES_BEAN " +
" ,DES_BUSINESS " +
" ,DES_DATABASE " +
" ,DES_DAO " +
" ,DES_UI " +
" ,DES_HTML " +
"from PROJETO ";
resultCommand = this.executeArray(command);
return resultCommand;
}
public ArrayList executeArray(String newComando) throws Exception
{
result = new ArrayList();
try
{
// Conecta no banco de dados
Connection conn = ConexaoMySQL.getConnection();
[/color][color=red]
Statement rs = conn.createStatement();[/color][color=brown]
ResultSet rset = rs.executeQuery(newComando);
this.result = this.montaArray(rset);;
// Fecha Connection e CallableStatement
ConexaoMySQL.closeConnection();
rs.close();
rset.close();
this.codErro = “0”;
return this.result;
}
catch(SQLException se)
{
this.codErro = Integer.toString(se.getErrorCode());
this.msgErro = se.getMessage();
// Fecha Connection e CallableStatement
ConexaoMySQL.closeConnection();
this.result = result;
return this.result;
}
}
=========================================[/color]