Guest User

Untitled

a guest
May 4th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import java.sql.ResultSet;
  6. import java.sql.ResultSetMetaData;
  7. import java.util.*;
  8. import java.io.*;
  9.  
  10. public class CreateInsert extends Object {
  11. public static void main (String args[]) {
  12.  
  13. //Create the connection
  14. String driverName = "org.postgresql.Driver";
  15. String connectURL = "jdbc:postgresql://localhost/postgres";
  16. String USERNAME = "postgres";
  17. String PASSWORD = "password";
  18. Connection con = null;
  19. try {
  20. Class.forName("org.postgresql.Driver");
  21. con = DriverManager.getConnection(connectURL, USERNAME, PASSWORD);
  22. } catch (ClassNotFoundException e) {
  23.                     System.out.println("Error creating class: "+e.getMessage());
  24.                     System.out.println("The Driver was not found, Please check diver location, classpath, username/password and server url settings");
  25.                     System.exit(0);
  26.             } catch (SQLException e) {
  27.                     System.out.println("Error creating connection: "+e.getMessage());
  28.                     System.exit(0);
  29.             }
Add Comment
Please, Sign In to add comment