Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JDBC Type Test Class
Got Connection.
driverName=PostgreSQL Native Driver
driverVersion=PostgreSQL 8.4 JDBC3 (build 701)
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
public class testJDBC {
public static void main(String[] args) throws Exception {
Connection conn = getPGSqlConnection();
System.out.println("Got Connection.");
DatabaseMetaData meta = conn.getMetaData();
try {
int jdbcMajorVersion = meta.getJDBCMajorVersion();
System.out.println("jdbcMajorVersion:" + jdbcMajorVersion);
} catch (Exception e) {
System.out.println("jdbcMajorVersion unsupported feature");
try {
int jdbcMinorVersion = meta.getJDBCMinorVersion();
System.out.println("jdbcMinorVersion:" + jdbcMinorVersion);
} catch (Exception e) {
System.out.println("jdbcMinorVersion unsupported feature");
String driverName = meta.getDriverName();
String driverVersion = meta.getDriverVersion();
System.out.println("driverName=" + driverName);
System.out.println("driverVersion=" + driverVersion);
public static Connection getPGSqlConnection() throws Exception {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://";
String username = "liferay-1";
String password = "liferay12345";
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.