Eclipse JDBC PostgreSQL Connection


Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DemoDB {
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/amazone_db", "postgres",
"admin");
PreparedStatement stmt = con.prepareStatement("select * from mail.role");
ResultSet Rs = stmt.executeQuery();
while (Rs.next()) {
System.out.println(Rs.getInt(1)+" "+Rs.getString(2));
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}

Configuration

Demo:



Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment