私は、データベースへの接続を作成し、クエリINTO INSERTを実行しようとしていますが、コードが実行されるとき、私はエラーを取得:あなたが見ることができるようにcom.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'BLUE'.
SQLクエリは、列名として値を見
を私のコードでは、 "BLUE"を列名の代わりに値として与えます。誰かが私が間違っていることを知っていますか? p.s. colorは列挙型であり、他のすべての値はdouble型です。
String query = "INSERT INTO [oval] " +
"(anchorX, anchorY, width, height, weight, color) VALUES " +
"(" + drawingItem.getAnchor().getX() +
", " + drawingItem.getAnchor().getY() +
", " + drawingItem.getWidth() +
", " + drawingItem.getHeight() +
", " + ((Oval) drawingItem).getWeight() +
", " + drawingItem.getColor().toString() + ")";
initConnection();
Statement myStmt = con.createStatement();
rowsAffected = myStmt.executeUpdate(query);
closeConnection();
EDITのANSWER:
String query = "INSERT INTO [oval] VALUES (?,?,?,?,?,?)";
initConnection();
PreparedStatement myPrepStmt = con.prepareStatement(query);
myPrepStmt.setDouble(1, drawingItem.getAnchor().getX());
myPrepStmt.setDouble(2, drawingItem.getAnchor().getY());
myPrepStmt.setDouble(3, drawingItem.getWidth());
myPrepStmt.setDouble(4, drawingItem.getHeight());
myPrepStmt.setDouble(5, ((Oval)drawingItem).getWeight());
myPrepStmt.setString(6, drawingItem.getColor().toString());
rowsAffected = myPrepStmt.executeUpdate();
closeConnection();
使用されるパラメータの代わりに、値を持つクエリ文字列をいじります。 –