-3
在MySQL創建表下面是我的代碼,顯示錯誤: 這是Netbeans的代碼連接我的測試數據庫,並創建表中它命名爲[R無法使用JDBC
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","tiger");
Statement stmt =con.createStatement();
String query = "create table r(s int);";
ResultSet rs = stmt.executeQuery(query);
this.dispose();
roll second = new roll();
second.setVisible(true);
} catch (Exception e) {
lbl1.setText("Error1 in database connectivity");
}
1)對代碼塊使用一致的邏輯縮進。代碼的縮進旨在幫助人們理解程序流程。 2)將catch(Exception e){..']形式的代碼更改爲catch(Exception e){e.printStackTrace(); //非常翔實! 3)爲了更好地幫助,請發佈[SSCCE](http://sscce.org/)。 –
您既不關閉連接,也不關閉語句。這將導致資源泄漏和內存問題。 –