我试图使用netbeans从SQLdatabase获取输出,代码在昨天完美运行,我没有对它进行任何更改,现在它还没有工作,mysql服务器启动并运行我可以从netbeans中的查询编辑器执行sql查询,但不能从我的java代码执行。请帮忙。
这里是代码
String dbURL = "jdbc:mysql://localhost:3306/Project1";
String username = "root";
String password = "";
Connection dbCon = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
dbCon = DriverManager.getConnection(dbURL, username, password);
stmt = dbCon.prepareStatement("SELECT itemname,priceperplate from rest WHERE ItemNo=4");
rs = stmt.executeQuery("SELECT itemname,priceperplate from rest WHERE ItemNo=4");
while (rs.next()) {
String itemname = rs.getString("ItemName");
String price = rs.getString("priceperplate");
System.out.println(price);
System.out.println(itemname);
}
} catch (Exception e) {
System.out.print("Exception");}