2015-12-02 90 views
0

我寫了一個非常簡單的數據庫使用JDBC的JDBC查詢。 這裏是代碼eclipse不顯示任何輸出

import java.sql.*; 
public class statement { 
    static final String JDBC_DRIVER="com.mysql.jdbc.Driver"; 
    static final String URL="jdbc:mysql://localhost/emp"; 
    static final String USER="root"; 
    static final String PAS="1234"; 
    public static void main(String [] args){ 
     System.out.println("hello"); 
     Connection con=null; 
     Statement stmt=null; 
     try{ 
      System.out.println("creating database connection"); 
      con=DriverManager.getConnection(URL,"root","1234"); 
      String sql="update Employee set age 30 where id =103"; 
      stmt=con.createStatement(); 
      Boolean ret=stmt.execute(sql); 
      System.out.println("return value is: "+ret.toString()); 
      int rows=stmt.executeUpdate(sql); 
      System.out.println("rows impacted: "+rows); 
      stmt.close(); 
      con.close(); 
     }catch(SQLException se) 
     { 
      System.out.println("hello"); 
     } 
    } 

}

在我的最後一個catch - 它只是檢查程序輸出任何東西。沒有錯誤,也沒有警告。但是,在我的控制檯窗口上,我收到

0 items 

消息。問題是什麼?

p.s.我將所有的jar文件包含到我的項目中

+2

你試過調試嗎?你不打印第一個「你好」嗎? – gonzo

+2

打印'0項目'的代碼在哪裏? – dave

+0

在控制檯上,根本沒有打印任何東西,那就是問題 –

回答

0

你能告訴我們你在命令行輸入的內容,或者你如何運行它?

我將它剪切/粘貼到Eclipse中,而不是丟失}。我得到了:

hello 
creating database connection 
hello 

第二個hello表示拋出SQLException,因爲我沒有在我的工作站上運行數據庫。 我在想也許你真的沒有java命令的權利。

+0

我不知道如何粘貼圖片。我在標籤上得到消息0項,輸出通常是不明確的 –