Created
August 5, 2011 12:39
-
-
Save amusarra/1127449 to your computer and use it in GitHub Desktop.
Classe di Test connessione JDBC verso un data base Oracle utilizzando il driver JDBC Thin.
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; | |
/** | |
* 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; | |
} | |
} |
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: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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment