Advertisement
Guest User

Main

a guest
Jan 4th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package test;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class Main {
  10.  
  11.     public static void main(String[] args) {
  12.        
  13.         try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5433/postgres","postgres", "Vietnammechkey 771993")) {
  14.            
  15.             System.out.println("Connected to PostgreSQL database!");
  16.             Statement stmt = connection.createStatement();
  17.             ResultSet rs = stmt.executeQuery("SELECT username FROM mstuser WHERE userid='1'");
  18.             while (rs.next()) {
  19.                   String username = rs.getString("username");
  20.                   System.out.println(username + "\n");
  21.                 }
  22.         }
  23.        
  24.         catch (SQLException e) {
  25.             System.out.println("Connection failure.");
  26.             e.printStackTrace();
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement