I was trying to execute the following code snippet in java when i encountered the following exception
String selectSQL = "select top 1 data_pkey " + "from products_data where pdt_fkey = ?"; java.sql.PreparedStatement preparedStatement = connection .prepareStatement(selectSQL); Logger.info(selectSQL); preparedStatement.setInt(1, pdt_fkey); ResultSet rsAlarm1 = preparedStatement.executeQuery(); if(rsAlarm1.next()) { _pkey = rsAlarm1 .getInt("data_pkey "); }Then I figured that when i did my insert into this table using preparedstatements i did n't do executeUpdate
// My problem inserts private static void insertDataIntoDB( int data_models_pkey, long a, long b, long c, Double d, Double e, String t) { try { Connection conAlarm = getAlarmConnection(); String insertSQL = "insert into data_models_data(data_models_fkey,data_model_max_val,r0,r1,r2,r3,r4) values(?,?,?,?,?,?,?)"; java.sql.PreparedStatement preparedStatement = conAlarm .prepareStatement(insertSQL); preparedStatement.setString(1, String.valueOf(data_models_pkey)); preparedStatement.setLong(2, a); preparedStatement.setString(3, String.valueOf(b)); preparedStatement.setString(4, String.valueOf(c)); preparedStatement.setString(5, String.valueOf(d)); preparedStatement.setString(6, String.valueOf(e)); preparedStatement.setString(7, String.valueOf(t)); preparedStatement.executeUpdate(); // This was missing. conAlarm.close(); } catch (SQLException e) { e.printStackTrace(); } }
No comments:
Post a Comment