Ao tentar executar a classe abaixo recebo o seguinte erro:
No suitable driver erro no conecta
java.lang.NullPointerException
at AcessConnector.getField(AcessConnector.java:53)
at AcessConnector.main(AcessConnector.java:69)
Exception in thread âmainâ
import java.sql.*;
public class AcessConnector {
final static private String dvr = âsun.jdbc.odbc.JdbcOdbcDriverâ;
final static private String url = âjdbc.odbc.rspâ;
private Connection con;
public boolean conecta(){
boolean retorno = true;
try {
Class.forName(dvr);
con = DriverManager.getConnection(url,"","");
}
catch (ClassNotFoundException er1){
System.out.println(er1.getMessage());
retorno = false;
}
catch (SQLException er2){
System.out.println(er2.getMessage() + " erro no conecta");
retorno = false;
}
return retorno;
}
public void desconecta(){
try{
con.close();
}
catch(SQLException er2){
System.out.println( er2.getMessage() + âerro no desconectaâ);
}
}
public String getField ( int num ){
try {
Statement stmt = con.createStatement();
String query = âSELECT * FROM AGENTESâ;
ResultSet rs = stmt.executeQuery(query);
String columvalue = rs.getString(num);
rs.close();
stmt.close();
return columvalue;
}
catch (SQLException er){
System.out.println(er.getMessage() + âerror no getFieldâ);
return âerror no getFieldâ;
}
}
public static void main (String [] args){
AcessConnector Acess = new AcessConnector();
Acess.conecta();
System.out.println(Acess.getField(1));
Acess.desconecta();
}
}
Alguem pode me disser o que estĂĄ errado? :?: :?: :?: :?: :?:
[quote=âLuiz-SPâ]
Ao tentar executar a classe abaixo recebo o seguinte erro:
No suitable driver erro no conecta
java.lang.NullPointerException
at AcessConnector.getField(AcessConnector.java:53)
at AcessConnector.main(AcessConnector.java:69)
Exception in thread âmainâ
import java.sql.*;
public class AcessConnector {
final static private String dvr = âsun.jdbc.odbc.JdbcOdbcDriverâ;
final static private String url = âjdbc.odbc.rspâ;
private Connection con;
public boolean conecta(){
boolean retorno = true;
try {
Class.forName(dvr);
con = DriverManager.getConnection(url,"","");
}
catch (ClassNotFoundException er1){
System.out.println(er1.getMessage());
retorno = false;
}
catch (SQLException er2){
System.out.println(er2.getMessage() + " erro no conecta");
retorno = false;
}
return retorno;
}
public void desconecta(){
try{
con.close();
}
catch(SQLException er2){
System.out.println( er2.getMessage() + âerro no desconectaâ);
}
}
public String getField ( int num ){
try {
Statement stmt = con.createStatement();
String query = âSELECT * FROM AGENTESâ;
ResultSet rs = stmt.executeQuery(query);
String columvalue = rs.getString(num);
rs.close();
stmt.close();
return columvalue;
}
catch (SQLException er){
System.out.println(er.getMessage() + âerror no getFieldâ);
return âerror no getFieldâ;
}
}
public static void main (String [] args){
AcessConnector Acess = new AcessConnector();
Acess.conecta();
System.out.println(Acess.getField(1));
Acess.desconecta();
}
}
Alguem pode me disser o que estĂĄ errado? :?: :?: :?: :?: :?:[/quote]
Olha o erro aqui:
final static private String url = "jdbc.odbc.rsp";
o correto Ă©:
final static private String url = "jdbc:odbc:rsp";
:oops: :oops: :oops:
Putz que vacilo. Valeu :lol:
Luiz-sp