2012-04-09 11 views
1

私のデータベースからmysqlをjTextareaにデータ(クエリの結果)を表示しようとすると問題が発生します。コンパイルすると次のようなエラー例外があります:私は名前が私のjTextFieldNomで書かれた名前である私のテーブルから「選択」クエリを使用している私のデータベースのJtextareaにデータを表示するには

SQL Exception: java.sql.SQLException: Can not issue SELECT via executeUpdate() 

が、これは私が解決する方法がわからないので、いくつかのいずれかが私を助けることを願って、私のコードです問題は、私は私のクエリが正しいと確信していますが、私は問題がどこにあるのかわかりません。

String pilote = "com.mysql.jdbc.Driver"; 
jComboBoxType.addItemListener(new ItemState()); 
jComboBoxMenaces.addItemListener(new ItemState()); 
try { 
    Class.forName(pilote); 
    Connection connexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root"," "); 

    Statement instruction = connexion.createStatement(); 
    String a=jTextFieldNom.getText(); 


    String SQL = "select description from table where nomcol="+a+";"; 
    ResultSet rs = instruction.executeQuery(SQL); 
    instruction = connexion.createStatement(); 


    int rowsEffected = instruction.executeUpdate(SQL); 
    jTextArea1.append(rs.getString("description"));          
} 
...... //bloc catch 

答えて

0

この行は、エラーをスローしているSelect文を実行しています。

int rowsEffected = instruction.executeUpdate(SQL); 

データベースを更新していないため、この行は必要ありません。

また、このお試しください

jTextArea1.setText(rs.getString("description")); 

をのsetTextに追加変更:おかげであなたの答えのためにeabrahamが、私は別の問題を持っている、あなたは私に言うと、私はMコードを変更したときに、私が持っている

String pilote = "com.mysql.jdbc.Driver"; 
jComboBoxType.addItemListener(new ItemState()); 
jComboBoxMenaces.addItemListener(new ItemState()); 
try { 
    Class.forName(pilote); 
    Connection connexion = DriverManager.getConnection(
     "jdbc:mysql://localhost:3306/test","root"," "); 

    Statement instruction = connexion.createStatement(); 
    String a=jTextFieldNom.getText(); 


    String SQL = "select description from table where nomcol="+a+";"; 
    ResultSet rs = instruction.executeQuery(SQL); 

    jTextArea1.setText(rs.getString("description"));          
} 
+0

を他の例外SQL例外:java.sql.SQLException: 'where句'の中の 'windows.exe'が不明ですが、なぜわかりません – hanem

+0

'テーブル'テーブルの詳細を投稿してください。あなたが照会しているテーブルについてもっと知る必要があります。 – eabraham

+0

OK、私のテーブルには、プロセスのリストがあります: – hanem

関連する問題