2011-02-27 237 views
0

我的代碼是:Java錯誤(類未找到)

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錯誤

什麼是錯的?你的問題的

+1

當代碼中出現粗心的拼寫錯誤時,很難認真考慮問題。 * grump * – skaffman 2011-02-27 13:36:37

+0

您應該打印出異常的堆棧跟蹤,它會爲您提供比「SQL錯誤」更有用/有用的信息。 – mtj8033 2011-02-27 13:28:31

回答

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"); 
} 

您的代碼拋出多半就是要告訴你的應用程序的問題是什麼的信息了。在每個println調用之後,添加一行以打印出堆棧跟蹤;例如

e.printStackTrace(System.out);