Guest User

Untitled

a guest
Aug 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package postgreTest;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8.  
  9. public class PostgreTest {
  10.     public static void main(String[] argv) {
  11.          
  12.         System.out.println("-------- PostgreSQL "
  13.                 + "JDBC Connection Testing ------------");
  14.  
  15.         try {
  16.  
  17.             Class.forName("org.postgresql.Driver");
  18.  
  19.         } catch (ClassNotFoundException e) {
  20.  
  21.             System.out.println("Where is your PostgreSQL JDBC Driver? "
  22.                     + "Include in your library path!");
  23.             e.printStackTrace();
  24.             return;
  25.  
  26.         }
  27.  
  28.         System.out.println("PostgreSQL JDBC Driver Registered!");
  29.  
  30.         Connection connection = null;
  31.  
  32.         try {
  33.  
  34.             connection = DriverManager.getConnection(
  35.                     "jdbc:postgresql://127.0.0.1:5432/sims", "postgres",
  36.                     "215922");
  37.  
  38.         } catch (SQLException e) {
  39.  
  40.             System.out.println("Connection Failed! Check output console");
  41.             e.printStackTrace();
  42.             return;
  43.  
  44.         }
  45.  
  46.         if (connection != null) {
  47.             System.out.println("You made it, take control your database now!");
  48.         } else {
  49.             System.out.println("Failed to make connection!");
  50.         }
  51.  
  52. //  try {
  53. ////        Statement statement = connection.createStatement();
  54. ////        ResultSet rs = statement.executeQuery("select * from sim;");
  55. ////       
  56. ////        while(rs.next()) {
  57. ////            System.out.println(rs.getString("id"));
  58. //      }
  59. //  } catch (SQLException e) {
  60. //      // TODO Auto-generated catch block
  61. //      e.printStackTrace();
  62. //  }
  63.    
  64.    
  65.     }
  66. }
Add Comment
Please, Sign In to add comment