java错误(找不到类)
我的代码是:java错误(找不到类),java,exception,Java,Exception,我的代码是: String baglantiURL="jdbc:postgresql://localhost:5432/Test"; String surucu="org.postgresql.Driver"; try{ Class.forName(surucu); Connection baglanti=DriverManager.getConnection(baglantiURL); Statement ifade=b
String baglantiURL="jdbc:postgresql://localhost:5432/Test";
String surucu="org.postgresql.Driver";
try{
Class.forName(surucu);
Connection baglanti=DriverManager.getConnection(baglantiURL);
Statement ifade=baglanti.createStatement();
String sorgu="select * from tablo";
ResultSet sonucKumesi=ifade.executeQuery(sorgu);
while (sonucKumesi.next()) {System.out.println(sonucKumesi.getString(1));
System.out.println(sonucKumesi.getString(2));
System.out.println(sonucKumesi.getString(3));
}
}
catch (ClassNotFoundException e) {
System.out.println("Class not found");
}
catch (SQLException e) {
System.out.println("SQL error");
}
catch (Exception e) {
System.out.println("hata");
}
}
输出为:
SQL错误
出了什么问题?问题的一部分在以下代码片段中:
catch (ClassNotFoundException e) {
System.out.println("Class not found");
}
catch (SQLException e) {
System.out.println("SQL error");
}
catch (Exception e) {
System.out.println("hata");
}
您的代码正在丢弃将告诉您应用程序的问题所在的大部分信息。在每次println
调用之后,添加一行以打印堆栈跟踪;e、 g
e.printStackTrace(System.out);
您的部分问题在以下代码段中:
catch (ClassNotFoundException e) {
System.out.println("Class not found");
}
catch (SQLException e) {
System.out.println("SQL error");
}
catch (Exception e) {
System.out.println("hata");
}
您的代码正在丢弃将告诉您应用程序的问题所在的大部分信息。在每次println
调用之后,添加一行以打印堆栈跟踪;e、 g
e.printStackTrace(System.out);
您应该打印出异常的堆栈跟踪,它将为您提供比“SQL错误”更有用的信息。当代码中存在粗心的打字错误时,很难认真对待问题。Grumpy您应该打印出异常的堆栈跟踪,它将为您提供比“SQL错误”更有用的信息。当代码中存在粗心的打字错误时,很难认真对待问题。发脾气