开发者

java error (Class not found)

My code is:

    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 (SQLE开发者_运维百科xception e) {
        System.out.println("SQL error");
    }
    catch (Exception e) {
                 System.out.println("hata");
    }
}

Output is:

SQL error

What is the wrong?


Part of your problem is in the following snippet:

catch (ClassNotFoundException e) {
    System.out.println("Class not found");
}
catch (SQLException e) {
    System.out.println("SQL error");
}
catch (Exception e) {
    System.out.println("hata");
}

Your code is throwing away most of the information that is going to tell you what the application's problem is. After each of the println calls, add a line to print out the stack trace; e.g.

    e.printStackTrace(System.out);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜