Issue in connecting Java thin driver in oracle 11G r2

我们两清 提交于 2019-12-10 14:58:08

问题


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


回答1:


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




回答2:


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

It has to be "host:port:sid"




回答3:


it should be

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




回答4:


Add the database SID in your connection string.

String url="jdbc:oracle:thin:@localhost:1521:SID_GOES_HERE";



回答5:


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



来源:https://stackoverflow.com/questions/13667815/issue-in-connecting-java-thin-driver-in-oracle-11g-r2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!