Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Asplode{
  4.   public static void main(String[] args) throws Exception{
  5.     Class.forName("org.postgresql.Driver").newInstance();
  6.  
  7.     Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost/david", "test", "test");
  8.  
  9.     connection.createStatement().execute("drop table if exists kittens");
  10.     connection.createStatement().execute("CREATE TABLE \"kittens\" (\"id\" SERIAL NOT NULL, \"name\" TEXT, \"created_at\" TIMESTAMP, PRIMARY KEY(\"id\"))");
  11.     PreparedStatement ps = connection.prepareStatement("INSERT INTO \"kittens\" (\"name\", \"created_at\") VALUES (?, ?) RETURNING \"id\"");
  12.  
  13.     int psCount = ps.getParameterMetaData().getParameterCount();
  14.  
  15.     ps.setString(1, "whiskers");
  16.     ps.setTimestamp(2, Timestamp.valueOf("2010-08-20 15:39:29.0"));
  17.  
  18.     ps.executeQuery();
  19. /*
  20. Exception in thread "main" java.lang.IllegalArgumentException: Can't change resolved type for param: 1 from 1043 to 25
  21.     at org.postgresql.core.v3.SimpleParameterList.setResolvedType(SimpleParameterList.java:230)
  22.     at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1488)
  23.     at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1062)
  24.     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
  25.     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
  26.     at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
  27.     at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
  28.     at Asplode.main(Asplode.java:18)
  29. */
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement