Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package JDBC;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Statement;
  6.  
  7. public class Insert_into
  8. {
  9.  
  10. public static void main(String args[])
  11. {
  12. Connection c = null;
  13. Statement stmt = null;
  14. try
  15. {
  16. Class.forName("org.postgresql.Driver");
  17. c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres",
  18. "1234");
  19.  
  20. System.out.println("Database open ok");
  21.  
  22. stmt = c.createStatement();
  23.  
  24. String sql = "INSERT INTO \"SEP\".members " + "VALUES (001, 'Premium', 'John Parker', 'Male', Birthdate, 'johnparker10@gmail.com', 8700, 'Horsens', 'VIA 12', 22668899, 1) ;";
  25. stmt.executeUpdate(sql);
  26.  
  27. // String sql1 = "INSERT INTO \"SEP\".membershipType (MembershipType, validity, PaymentMethod, StartDate, EndDate, MembershipCost) VALUES "
  28. // + " (GUI) ";
  29. // stmt.executeUpdate(sql1);
  30. //
  31. // String sql2 = "INSERT INTO \"SEP\".trainer (TrainerID, TrainerName, Program,) VALUES "
  32. // + " (GUI) ";
  33. // stmt.executeUpdate(sql2);
  34.  
  35. // String sql = "UPDATE \"SuppParts\".staff set saltopay = 12500.00 where staffno = 'KS03';";
  36. // stmt.executeUpdate(sql);
  37.  
  38. stmt.close();
  39. c.close();
  40. } catch (Exception e)
  41. {
  42. System.err.println(e.getClass().getName() + ": " + e.getMessage());
  43. System.exit(0);
  44. }
  45. System.out.println("Database update ok");
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement