postgis JDBC
postgis进行jdbc连接时,应在classpath和项目对应的WEB-INF/lib下同时引入jar包,否则就会找不到
具体连接代码为:
Connection c = null;
Statement stmt = null;
try {
Class.forName(“org.postgresql.Driver”);
c = DriverManager.getConnection(“jdbc:postgresql://localhost:5432/spatial”, “postgres”, “123456”);
c.setAutoCommit(false); // 把自动提交
System.out.println(“Opened database successfully”);
stmt = c.createStatement();
String sql = “CREATE TABLE STUDENTS ” +
“(ID TEXT PRIMARY KEY NOT NULL ,” +
” NAME TEXT NOT NULL, ” +
” SEX TEXT NOT NULL, ” +
” AGE TEXT NOT NULL)”;
stmt.executeUpdate(sql);
System.out.println(“Table created successfully”);
stmt.close();
c.commit();
c.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + “: ” + e.getMessage());
System.exit(0);
}
转载自:https://blog.csdn.net/A873054267/article/details/78353525