0

Here is the Java test code I wrote. It takes about 40 seconds to connect to the Oracle database using JDBC, but similar code in C# using the OracleConnection.Open method completes in less than 1 second. Does anyone know what might be causing this difference?

LocalDateTime startTime=LocalDateTime.now();
//Class.forName("oracle.jdbc.driver.OracleDriver");
String connectionUrl="jdbc:oracle:thin:@//192.168.1.100:1521/ORCL";
DriverManager.getConnection(connectionUrl, "TEST_USER", "******");
//java.util.Properties properties = new Properties();
//properties.put("user","TEST_USER");
//properties.put("password","******");
//new oracle.jdbc.OracleDriver().connect(connectionUrl, properties);
LocalDateTime endTime=LocalDateTime.now();
System.out.println("elapsed time:"+ Duration.between(startTime, endTime).getSeconds()+"seconds");

The JDBC library I'm using is ojdbc8, version 23.26.0.0.0. I also switched to the latest version of ojdbc14 for testing, and the result was the same.

The Java version is JDK 1.8, and the Oracle database version is 11g.

10
  • Class.forName(JDBC_DRIVER) no longer needed Commented Nov 14 at 8:57
  • Is there a reason you're using the // in the JDBC URL? Do things improve if you remove it? Commented Nov 14 at 8:59
  • @Luke Woodward Just now ,I have test that I change the url jdbc:oracle:thin:@//192.168.1.100:1521/ORCL to jdbc:oracle:thin:@192.168.1.100:1521/ORCL and run the code. the result is the same. Commented Nov 14 at 9:06
  • 1
    @Abra Although Class.forName is no longer needed (assuming the driver is on the initial classpath), it doesn't hurt either (and can help with identifying classpath or other classloading issues). Commented Nov 14 at 14:01
  • 1
    @LukeWoodward The difference is that @//192.168.1.100:1521/ORCL identifies the service ORCL, while @192.168.1.100:1521/ORCL would be invalid (or at least, should be AFAIK); there is an @192.168.1.100:1521:ORCL, but then ORCL would be an SID, not a service name. Commented Nov 14 at 14:04

1 Answer 1

0

Your code is ok. Your driver is a 0.0.0. version. Never use this kind of version. Specially if it was released a couple of weeks ago.

Always remember:

mayor.minor.(version).revision.build

Last three numbers should be > 0

Check mvnrepository.com and get a previous version with better (higher) last 3 numbers

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.