I have a spring boot 1.5.22 app and i am trying to connect to oracle 10g with tomcat-jdbc and ojdbc6.
i have the datasource getproperties() function to connect to my db :
DataSource dataSourceProperties() {
DataSource ds=null;
try {
ds = DataSourceBuilder.create()
.driverClassName("oracle.jdbc.OracleDriver")
.url("jdbc:oracle:thin:@//host:port/DBname")
.username("xxx")
.password("xxx")
.build();
}catch (Exception e) {
System.out.println(e.toString());}
when the url was with this SID format : jdbc:oracle:thin:@host:port:DBname i got an oracle error : refused:ROR=(code=12505)(EMFI=4) when i changed it to jdbc:oracle:thin:@host:port/DBname i got java.sql.SQLException: String index out of range: -1 and finally this format jdbc:oracle:thin:@//host:port/DBname and still getting java.sql.SQLException: String index out of range: -1
that's how i make call to that function in getConnection function :
public Connection getConnection() throws SQLException
{
Connection conn=null;
try {
this.ds=this.dataSourceProperties();
conn=ds.getConnection();
}catch (SQLException e ) {
System.out.println(e.toString());
}
return conn;}
here are somme error logs :
2021-08-16 18:33:59.926 ERROR 22476 --- [bio-8080-exec-1] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: String index out of range: -1
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:332) ~[tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212) ~[tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.43.jar:na]
at com..web.services.DBConnection.getConnection(DBConnection.java:68)
[classes/:na]
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
java.sql.SQLException: String index out of range: -1
Mon Aug 16 18:33:59 CEST 2021
java.lang.NullPointerException
here are new error logs after modifying the url to the correct format jdbc:oracle:thin://xx:1509/xxx
2021-08-17 11:25:27.368 ERROR 15440 --- [bio-8080-exec-5] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: Connection refused: connect
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:223) ~[jdbc-oracle-11.2.0.3.jar:na]
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:100) ~[jdbc-oracle-11.2.0.3.jar:na]
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:146) ~[jdbc-oracle-11.2.0.3.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319) ~[tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212) ~[tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.43.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.43.jar:na]
Solved : this one worked for me :)
jdbc:oracle:thin://host:port/ServiceName
An example:
jdbc:oracle:thin://hostname:1509/ServiceName(or DatabaseName)