Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Asplode{
- public static void main(String[] args) throws Exception{
- Class.forName("org.postgresql.Driver").newInstance();
- Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost/david", "test", "test");
- connection.createStatement().execute("drop table if exists kittens");
- connection.createStatement().execute("CREATE TABLE \"kittens\" (\"id\" SERIAL NOT NULL, \"name\" TEXT, \"created_at\" TIMESTAMP, PRIMARY KEY(\"id\"))");
- PreparedStatement ps = connection.prepareStatement("INSERT INTO \"kittens\" (\"name\", \"created_at\") VALUES (?, ?) RETURNING \"id\"");
- int psCount = ps.getParameterMetaData().getParameterCount();
- ps.setString(1, "whiskers");
- ps.setTimestamp(2, Timestamp.valueOf("2010-08-20 15:39:29.0"));
- ps.executeQuery();
- /*
- Exception in thread "main" java.lang.IllegalArgumentException: Can't change resolved type for param: 1 from 1043 to 25
- at org.postgresql.core.v3.SimpleParameterList.setResolvedType(SimpleParameterList.java:230)
- at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1488)
- at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1062)
- at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
- at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
- at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
- at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
- at Asplode.main(Asplode.java:18)
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement