JDBC 快速入门
在项目中导入jar包 “pinusdb_jdbc_1.x.x.jar” 即可。
public class Test {
public static void printResultSet(ResultSet rs) throws SQLException {
ResultSetMetaData rsMeta = rs.getMetaData();
int colCnt = rsMeta.getColumnCount();
for(int i = 1; i <= colCnt; i++) {
System.out.print("--");
System.out.print(rsMeta.getColumnName(i));
System.out.print(",");
System.out.print(rsMeta.getColumnTypeName(i));
System.out.print("--|");
}
System.out.println();
while(rs.next()) {
for(int i = 1; i <= colCnt; i++) {
System.out.print(rs.getObject(i).toString());
System.out.print(" | ");
}
System.out.println();
}
}
public static void Query(String connStr, String querySql) {
try {
Connection conn = DriverManager.getConnection(connStr);
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(querySql);
printResultSet(rs);
rs.close();
conn.close();
} catch (SQLException ex) {
System.out.println("Exception:");
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) throws ClassNotFoundException {
Class.forName("cn.pinusdb.jdbc.PDBDriver");
String connStr = "jdbc:pinusdb://127.0.0.1:8105?user=sa&password=pinusdb";
Query(connStr, "select * from sys_table");
}
}