To establish an Oracle thin JDBC connection to a TNS alias (tnsname), make sure you pass the oracle.net.tns_admin system property to the JVM. Its value should be the directory in which your tnsnames.ora file is located. After that, you can just pass the TNS alias in place of the host name in the JDBC URL.
E.g. if you simply try to connect to jdbc:oracle:thin:@MYDB, which is in your tnsnames.ora file, you’ll get an SQLException with a detail message of Io exception: Unknown host specified. If you fire up the JVM with a -Doracle.net.tns_admin=/oracle/10g/NETWORK/ADMIN, or use System.setProperty(String,String) after startup, the connection will be established successfully.
Oh yeah? Well what’s this SQLException “Io exception: SO Exception was generated“, then? you ask? The exception message is a bit deceptive, as the “SO” suggests OCI when we’re really using thin. I encountered this exception with the ojdbc14.jar included with OC4J standalone 10.1.3.1.0. Using the JDBC driver from the Oracle client 10.2 package stops it occuring, but causes OC4J standalone to log a warning about a missing getStatistics method every few seconds, which is hardly any less annoying. I’m not sure what’s causing it to happen, but a version upgrade seems to fix it. If that’s not an option, you can always use good old jdbc:oracle:thin:@host:port/service, which is what I settled for in the end.
分享到:
相关推荐
jdbc:oracle:thin:@<TNSName> ``` 例如: ```java jdbc:oracle:thin:@GL ``` 这里的`GL`是tnsnames.ora文件中定义的TNS别名。 ### 测试和配置 在测试JDBC连接时,需要确保Oracle监听器(Listener)和相关配置文件...
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@hostname:port/service_name", "username", "password"); ``` 这里的`hostname`是数据库服务器的地址,`port`是监听的端口,`service_name`是...
1. 加载驱动:`Class.forName("oracle.jdbc.driver.OracleDriver");` 2. 创建连接:`Connection conn = DriverManager.getConnection(url, username, password);` 3. 执行SQL:`Statement stmt = conn....
例如,一个典型的JDBC连接URL可能是`jdbc:oracle:thin:@hostname:port/service_name`。 为了实现数据库操作,开发者会使用`java.sql`包中的接口,如`Connection`、`Statement`、`PreparedStatement`和`ResultSet`。...
- 连接字符串通常包含 TNS(Transparent Network Substrate)名称,如:`jdbc:oracle:oci8:@tnsname` 在 Oraclelib 压缩包中,可能包含了以下文件: - `ojdbc14.jar`:这是 Oracle 10g JDBC Thin 驱动的主要 JAR ...
String url = "jdbc:oracle:thin:@//your_db_host:port/service_name"; String username = "your_username"; String password = "your_password"; try { Class.forName("oracle.jdbc.driver.OracleDriver"); ...
Oracle JDBC 连接池和缓存是数据库管理中优化数据库访问效率的重要机制。在Java应用程序中,使用JDBC(Java Database Connectivity)与Oracle数据库交互时,通过连接池可以有效地管理和复用数据库连接,减少每次建立...
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//hostname:port/service_name", "sys as sysdba", "password"); ``` 这里的URL格式是`jdbc:oracle:thin:@//hostname:port/service_name`,...
"jdbc:oracle:thin:@hostname:port/service_name", "username", "password"); ``` 此外,JDBC驱动还支持多种特性,如批处理操作、预编译语句、结果集缓存、游标和存储过程调用等。开发者可以根据需求选择合适的...
1. 加载驱动:使用`Class.forName()`方法加载对应的Oracle JDBC驱动类。 2. 创建连接:调用`DriverManager.getConnection()`方法,传入数据库URL、用户名和密码来建立连接。 3. 执行SQL:通过`Connection`对象创建`...
在上述代码中,`"jdbc:oracle:thin:@//hostname:port/service_name"`是连接URL,需要替换为实际的Oracle服务器信息,`username`和`password`是数据库登录凭证。 总的来说,正确选择和使用Oracle数据库驱动是Java...
3. 如果使用的是Oracle 11g Release 2,确保使用`/`而不是`:`分隔`HOSTNAME:PORTNUMBER`和`SID`,例如:`jdbc:oracle:thin:@//hostname:port/sid`。 连接数据库时,还需要提供用户名和密码: ```java String USER_...
"classes12"通常指的是Oracle JDBC Thin驱动,这是一个纯Java实现的驱动,不需要Oracle客户端软件即可运行。它通过网络直接与Oracle数据库服务器通信,实现了轻量级的数据库连接方式。 Thin驱动的工作原理是:Java...
String url = "jdbc:oracle:thin:@<ip>:<port>:<service_name>"; String username = "<your_username>"; String password = "<your_password>"; Connection conn = DriverManager.getConnection(url, username, ...
- 如果使用的是 Oracle 12c 或更高版本,建议使用 `TNS` 形式的 URL,即 `jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=...
jdbc:oracle:thin:@<hostname>:<port>:<service_name> ``` `<hostname>`是Oracle服务器地址,`<port>`是监听的TNS端口,通常为1521,`<service_name>`是数据库服务名。 3. **SQLite JDBC驱动**:SQLite是一个轻...
有不同类型的JDBC驱动,如 Thin driver、Thin JDBC driver 和 OCI JDBC driver,它们分别有不同的连接方式和性能特点。 5. **PL/SQL Developer Tools**:这些工具支持PL/SQL编程,包括PL/SQL编译器、调试器和性能...
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); conn = DriverManager.getConnection(dbUrl, theUser, thePw); state = conn.createStatement(); } catch (Exception e) { e....
- **配置URL**:连接字符串必须指明数据库服务名(SID)或服务标识(Service Name),例如`jdbc:oracle:thin:@hostname:port/service_name`。 - **认证信息**:提供正确的用户名和密码以进行数据库身份验证。 - **类...