Created
June 15, 2011 13:54
-
-
Save amusarra/1027141 to your computer and use it in GitHub Desktop.
JDBC Type Test Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Got Connection. | |
jdbcMajorVersion:3 | |
jdbcMinorVersion:0 | |
driverName=PostgreSQL Native Driver | |
driverVersion=PostgreSQL 8.4 JDBC3 (build 701) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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