利用postgresql-42.2.14.jre7.jar版本的jdbc连接本机postgresql数据库!代码如下:
**
**package testJdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class jdbcTest {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName(“org.postgresql.Driver”);
conn = DriverManager.getConnection(“jdbc:postgresql://localhost:5432/Test”,“postgres”,“postgresql”);
System.out.println(“连接数据库成功!”);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(“select * from jjj;”);
while(rs.next()){
int id = rs.getInt(“gid”);
String name = rs.getString(“sheet1__sh”);
System.out.println(“id=”+id+ " name="+name);
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
数据库结构图
查询效果