import java.sql.*;
public class JavaApp {
public static void main(String args[]) {
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://172.28.31.191:5432/mydb123","postgres", "postgres");
c.setAutoCommit(false);
stmt = c.createStatement();
String sql = "SELECT count(*) from COMPANY ";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getInt(1));
}
rs.close();
stmt.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": " +e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
}
java学习笔记(十) -- java和PostgreSQL的连接
最新推荐文章于 2024-02-29 10:21:59 发布