0

I am trying to execute this sql code in java but after it executes, I need to set it to a value im trying to enter into a table.

st = "INSERT INTO master_st4(unix_timestamp, hrap_xy, rain) values(?, ?, ?)";
state = connection.prepareStatement(st);
state.setInt(1, "select extract (epoch from '2014-03-01 06:00:00 UTC':: timestamp with time zone)");
state.setInt(2, in);
state.setDouble(3, arrBDS);                    
state.executeUpdate();

I know this returns something else than an integer, but I need a integer to pass into the first of the three set statements. unix_timestamp is an integer, hrap_xy is an integer, rain is a real number so double.

Here is the error message:

Exception in thread "main" java.lang.NumberFormatException: For input string: "select extract (epoch from '2014-03-01 06:00:00 UTC':: timestamp with time zone)" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at JgribDEX.main(JgribDEX.java:110)

1 Answer 1

1

What if you put the subquery right into the query like so:

st = "INSERT INTO master_st4(unix_timestamp, hrap_xy, rain) values((select extract (epoch from '2014-03-01 06:00:00 UTC':: timestamp with time zone)), ?, ?)";
state = connection.prepareStatement(st);
state.setInt(1, in);
state.setDouble(2, arrBDS);                    
state.executeUpdate();
Sign up to request clarification or add additional context in comments.

1 Comment

Yes. Thanks I swear I tried this, I guess I didn't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.