Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 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", "david", "fish");
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement