understanding Java JDBC error

后端 未结 4 1689
野性不改
野性不改 2021-01-28 16:29

I was hoping to have some assistance in understanding this error. I am making a simple connection to a database, and for some reason it doesn\'t like my input, but I am failing

4条回答
  •  孤独总比滥情好
    2021-01-28 16:44

    Never use plain statements with substitution. Use preparedStatement instead [ Read: When should we use a PreparedStatement instead of a Statement? ]

        String sql = "insert into MYTABLE_TRANSACTIONS (ACCOUNT_ID,TRANSACTION_TYPE,AMOUNT) values (?, ?, ?)";
        PreparedStatement pstmt = connection.prepareStatement(sql);
        pstmt.setString(1, name );
        pstmt.setString(2, action );
        pstmt.setDouble(3, amount);
    pstmt.executeUpdate();
    

提交回复
热议问题