Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in connecting Java thin driver in oracle 11G r2

public static  Connection getConnection()throws SQLException,ClassNotFoundException
       { String username="scott";
            String password="tiger";

            String url="jdbc:oracle:thin:@localhost:1521";
        Connection connection = null;
        System.out.println("before class");
                   Class.forName("oracle.jdbc.OracleDriver");
                   System.out.println("Before connection");
                connection=DriverManager.getConnection(url,username,password);
           System.out.println("CONNECTED");
        return connection;
       }

Connection Name: orcl UserName:scott Password:tiger connection details:scott@

I am using Oracle g11 Release 2 and I already included the ojdbc.jar in my build path. When trying to establish the connection, I get the following stack trace error:

java.sql.SQLException: Io exception: Invalid connection string format, a valid format is: "host:port:sid" at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:404) at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.adobe.util.DBConnection$DBUtil.getConnection(DBConnection.java:23) at com.adobe.daoimpl.DBimplementation.registration(DBimplementation.java:21) at com.adobe.service.AdobeService.registration(AdobeService.java:13) at webservice.Web.service(Web.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

Thanks in advance

like image 649
Kali Avatar asked Dec 02 '12 09:12

Kali


5 Answers

Just solved this issue by using: jdbc:oracle:thin:@//ipadress:portnumber/service_name

like image 145
Gleidson Cardoso da Silva Avatar answered Nov 17 '22 07:11

Gleidson Cardoso da Silva


You are missing SID (or service name) on the end of connection string.

It has to be "host:port:sid"

like image 26
jakub.petr Avatar answered Nov 17 '22 07:11

jakub.petr


it should be

String url=" jdbc:oracle:thin:@Localhost:1521:XE";

like image 37
smita Avatar answered Nov 17 '22 05:11

smita


Add the database SID in your connection string.

String url="jdbc:oracle:thin:@localhost:1521:SID_GOES_HERE";
like image 36
Kevin Bowersox Avatar answered Nov 17 '22 05:11

Kevin Bowersox


And your SID probably is XE, so it should be jdbc:oracle:thin:Localhost:1521:XE

like image 1
sorencito Avatar answered Nov 17 '22 07:11

sorencito