JDBC连接之PostgreSQL数据库

String sql = "select * from test";

// 连接字符串,格式: "jdbc:数据库驱动名称://数据库服务器ip/数据库名称"
String url = "jdbc:postgresql://localhost/soft";
String username = "scott";
String password = "tiger";

Class.forName(""org.postgresql.Driver").newInstance();

Connection conn = DriverManager.getConnection(url, username, password); 
Statement  stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE
                                     , ResultSet.CONCUR_UPDATABLE);
ResultSet  rs   = stmt.executeQuery(sql);

rs.close();
stmt.close();
conn.close();

你可能感兴趣的:(Java)