Reputation: 31
Oracle has declared that 11g R2 has support IPV6 and ojdbc6.jar is the right one.
But when I test it, I get exception, have you solved that?
My test code is:
import java.sql.SQLException;
import java.util.Properties;
public class Test {
final static String sDBDriver = "oracle.jdbc.driver.OracleDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
java.sql.Connection conn=null;
String url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=
[fe80::b056:5cff:fe78:b672])(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=fnstdb1))";
try
{
Class.forName(sDBDriver);
conn = DriverManager.getConnection(url,"scott","fnst1234");
}
catch (Exception e)
{
System.out.println("ERROR:"+e.getMessage());
}
finally
{
System.out.println("连接是否关闭:"+conn.isClosed());
conn.close();
}
}
}
and I use the following cmd:
java -cp ojdbc6.jar -Djava.net.preferIPv6Addresses=true Test
but the result is: ERROR:NL Exception was generated
What is wrong?
Upvotes: 2
Views: 2508
Reputation: 31
I have solved this problem .the following shows what have I done:
edit $DB_HOME\NETWORK\ADMIN\listener.ora
file to allow the oracle to listen on the ip and port. for example: (ADDRESS = (PROTOCOL = TCP)(HOST = [fe80::221:97ff:fe66:1fa9%4])(PORT= 1521))
Reatart the listener. Run: LSNRCTL stop/start
In some applications (javase, connection-pool, lookup)use ojdbc6.jar: jdbc:oracle:thin:@[fe80::221:97ff:fe66:1fa9]:1521:orcl
.
The result is successful!!
the ip address in listener.ora must add "%4" ,or it will fail.
ipv6 address must in "["and "]",or it will fail.
the document of oracle declares that using ipv6 must set the jvm options
java.net.preferIPv6Addresses=true
but it does not matter whether it sets or not!
Upvotes: 1