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", "david", "fish");
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement