Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Main {
- public static void main(String[] args) {
- try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5433/postgres","postgres", "Vietnammechkey 771993")) {
- System.out.println("Connected to PostgreSQL database!");
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT username FROM mstuser WHERE userid='1'");
- while (rs.next()) {
- String username = rs.getString("username");
- System.out.println(username + "\n");
- }
- }
- catch (SQLException e) {
- System.out.println("Connection failure.");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement