2017-12-16 19 views
-1

こんにちは私は私のJavaコードの構文に問題があります。私はtableview SQLデータベースからそのデータを取得している。私はデータベースに3つのテーブルを作成しましたbookcustomerorder。ボタンをクリックすると、選択した書籍を取り出してorderテーブルに追加します。ここ
メインプログラム(DBからメソッドを呼び出す)のコードは次のとおりJava JDBC Derby構文エラー

if(table.getSelectionModel().getSelectedItems().iterator().hasNext()) { 
        db.insertOrder(new Bestellung(customerid,table.getSelectionModel().getSelectedItems().iterator().next())); 

テーブルbookが固定されています。他の2つのテーブルcustomerorderは動的です。

問題:

私はこのようorderテーブルに挿入この

String ct = "CREATE TABLE Order (" + "Order_Id integer generated always as identity, " + "CUSTOMER_ID BIGINT" + "ISBN, CHAR(13) " + "PRIMARY KEY(Order_Id))"; 

ようorder表中の値のように...

を作成します。 (ここでは、コンパイラは、それが動作しないと言うの位置だString iに構文の問題がある。)

String i = "INSERT INTO ORDER(CUSTOMER_ID,ISBN), VALUES(?,?)"; 
    Connection conn = null; 
    PreparedStatement stmt = null; 
    try { 
     conn = DriverManager.getConnection(connString); 
     stmt = conn.prepareStatement(i); 
     conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
     stmt.setLong(1, order.getCustomerId()); 
     stmt.setString(2, order.getBuch().getISBN()); 
     stmt.executeUpdate(); 
    } catch (SQLException e) { 
     System.out.println(e.getMessage()); 
     e.printStackTrace(); 
    } 
    finally { 

     try { 
      if (stmt != null) 
       stmt.close(); 
      if (conn != null) 
       conn.close(); 
     } catch (SQLException e) { 
      System.out.println(e.getMessage()); 
      e.printStackTrace(); 
     } 
    } 

と、ここで私は、どのように

Syntax error: Encountered "ORDER" at line 1, column 13.

を得た構文エラーです私はstring iで私の構文を修正する必要がありますか?誰にもアイデアはありますか?

+0

Orderの名前を持つテーブルを作成できますか? –

+0

ああ、名前 'オーダー'もできませんでした。この単語のように思えますが、私はそれを変更しました – Ikarus

+0

SQLで予約されています。今それはありがとう – Ikarus

答えて

1
INSERT INTO ORDER(CUSTOMER_ID,ISBN), VALUES(?,?) 
           ^

カンマは余分です。また、あなたの中でCREATE TABLE

... + "ISBN, CHAR(13) " + ... 
     ^

このコンマも無関係です。

+0

感謝作品 – Ikarus

0

あなたがテーブル名として予約語/キーワードを使用する場合は、必要があります。

  1. MySQLの:のような使用 "、::select * from "Order"
select * from 'Order'
  • オラクル、PostgreSQLの:のような使用 '、

    しかし、それは悪い習慣がある、あなたのテーブル名を変更してみてください。

    をあなたがすることを別のエラーを持っています@ジム・ギャリソンによって振られた。

  • 関連する問題