Classe di Test connessione JDBC verso un data base Oracle utilizzando il driver JDBC Thin.
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
/**
* Classe di Test connessione JDBC verso un data base Oracle
* utilizzando il driver JDBC Thin.
*
* @author amusarra
*
*/
public class testJDBCOracle {
public static void main(String[] args) throws Exception {
Connection conn = getORASqlConnection();
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();
String databaseProductVersion = meta.getDatabaseProductVersion();
System.out.println("driverName=" + driverName);
System.out.println("driverVersion=" + driverVersion);
System.out.println("databaseProductName=" + databaseProductVersion);
conn.close();
}
public static Connection getORASqlConnection() throws Exception {
String driver = "oracle.jdbc.OracleDriver";
String url = "jdbc:oracle:thin:@liferay-portal-db-1.local:1521:XE";
String username = "liferayce6";
String password = "liferay12345";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
}
Got Connection.
jdbcMajorVersion:11
jdbcMinorVersion:2
driverName=Oracle JDBC driver
driverVersion=11.2.0.1.0
databaseProductName=Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Beta