Skip to content

Instantly share code, notes, and snippets.

@amusarra
Created June 15, 2011 13:54
Show Gist options
  • Save amusarra/1027141 to your computer and use it in GitHub Desktop.
Save amusarra/1027141 to your computer and use it in GitHub Desktop.
JDBC Type Test Class
Got Connection.
jdbcMajorVersion:3
jdbcMinorVersion:0
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);
conn.close();
}
public static Connection getPGSqlConnection() throws Exception {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://192.168.56.101:5432/liferay-1?charSet=UTF-8";
String username = "liferay-1";
String password = "liferay12345";
Class.forName(driver);
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