简体   繁体   English

Java错误(找不到类)

[英]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 (SQLException e) {
        System.out.println("SQL error");
    }
    catch (Exception e) {
                 System.out.println("hata");
    }
}

Output is: 输出为:

SQL error SQL错误

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; 在每个println调用之后,添加一行以打印出堆栈跟踪; eg 例如

    e.printStackTrace(System.out);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM