看板 java 關於我們 聯絡資訊
可以成功連上資料庫但是在執行stmt的時候,會錯誤。 請問可能是那邊出問題呢? 謝謝! try { Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e) { System.out.println("找不到驅動程式類別"); } try { Connection conn = DriverManager.getConnection(url,user,password); if(!conn.isClosed()) System.out.println("資料庫連線成功"); try{ Statement stmt = conn.createStatement(); stmt.executeUpdate("SELECT nodeId from node"); stmt.close(); } catch (SQLException s){ s.printStackTrace(); } conn.close(); } catch(SQLException e) { System.out.println("error"); } stmt.executeQuery("SELECT nodeId from node"); 才對。 沒看過JDBC的書,隨便google 網頁code 來修改! 想不到是語法錯了....sori -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.199.160
moonjuice:如果是連外部的資料庫..要確定該使用者帳號的主機位置有 10/27 01:45
moonjuice:沒有限定 另外,可以在catch事件後直接列印事件內容看看 10/27 01:47
moonjuice:或許會有幫助 ^ ^ 10/27 01:48
※ 編輯: poc7667 來自: 140.113.199.160 (10/27 08:18) ※ 編輯: poc7667 來自: 140.113.199.160 (10/27 08:26)