Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.*;
- public class exercise_2_kyoung27
- {
- public static void main(String [] argv) throws Exception
- {
- //scanner object for keyboard input, database/username/password
- Scanner keyboard = new Scanner(System.in);
- System.out.print("database: ");
- String database = keyboard.nextLine();
- System.out.print("user: ");
- String user = keyboard.nextLine();
- System.out.print("password: ");
- String password = keyboard.nextLine();
- Connection conn = null;
- try
- {
- Class.forName("org.postgresql.Driver");
- String url = "jdbc:postgresql://localhost/"+database;
- conn = DriverManager.getConnection(url, user, password);
- }
- catch (ClassNotFoundException e)
- {
- e.printStackTrace();
- System.exit(1);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- System.exit(2);
- }
- //Now we're connected up lets retrieve a list of employees
- Statement stmt = null;
- try
- {
- //statement object for inserting
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
- //returns all records from table?
- ResultSet uprs = stmt.executeQuery("SELECT * FROM Movie");
- //create new row in ResultSet object
- uprs.moveToInsertRow();
- //add new movie data
- uprs.updateInt("movie_id", 76568769);
- //insert the new row
- uprs.insertRow();
- uprs.beforeFirst();
- }
- catch (SQLException e)
- {
- System.out.println(e);
- conn.close();
- System.exit(1);
- }
- System.out.println("yay this worked!");
- conn.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement