我有一个与oracle DB的jdbc连接;
if(connection == null || connection.isClosed()) {
try {
connection = null;
connection = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/ORCL", "usr", "pass");
} catch(Exception e) {
e.printStackTrace();
throw e;
}
当Camunda服务器启动并尝试获取连接时,它会抛出:
java.sql.SQLRecoverableException:IO错误:端口的数字格式无效 oracle.jdbc.driver.T4CConnection.logon上的数字(T4CConnection.java:774) at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691) at java.sql.DriverManager.getConnection(Unknown Source) 在java.sql.DriverManager.getConnection(未知来源)
甚至在表达式选项卡(eclispe)中它告诉我它可以获得连接...但是当我在调试器中查看DriverManager时它会抛出错误并且连接为空...有人可以帮助我吗?
我在服务器中有ojdc驱动程序,而我使用ojdc8的类路径,我在SpringBoot应用程序上使用完全相同的连接,它没有任何问题;
谢谢!
答案 0 :(得分:0)
问题解决了!
首先需要通过反射获取jdbc驱动程序类,当我启动SpringBoot应用程序时,Spring会自动创建类
if(connection == null || connection.isClosed()) {
try {
connection = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/ORCL","usr","pass");
}
catch(Exception e) {
e.printStackTrace();
throw e;
}
}
return connection;