在oracle 11G r2中连接Java瘦驱动程序的问题

时间:2012-12-02 09:00:22

标签: java oracle11g thin sqlexception

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;
       }

连接名称:orcl 用户名:斯科特 密码:虎 连接细节:scott @

我正在使用Oracle g11 Release 2,我已经在构建路径中包含了ojdbc.jar。尝试建立连接时,出现以下堆栈跟踪错误:

  

java.sql.SQLException:Io异常:无效的连接字符串格式,   有效格式为:“host:port:sid”at   oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)at at   oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)at at   oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)at at   oracle.jdbc.driver.OracleConnection。(OracleConnection.java:404)     在   oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)     在oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)at   java.sql.DriverManager.getConnection(未知来源)at   java.sql.DriverManager.getConnection(未知来源)at   com.adobe.util.DBConnection $ DBUtil.getConnection(DBConnection.java:23)     在   com.adobe.daoimpl.DBimplementation.registration(DBimplementation.java:21)     在com.adobe.service.AdobeService.registration(AdobeService.java:13)     在webservice.Web.service(Web.java:16)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)     在   org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)     在   org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)     在   org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)     在org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)at   org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)at at   org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)     在org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)at   org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:647)at   org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:728)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

提前致谢

6 个答案:

答案 0 :(得分:6)

使用:jdbc:oracle:thin:@//ipadress:portnumber/service_name

解决了这个问题

答案 1 :(得分:3)

您在连接字符串末尾缺少SID(或服务名称)。

必须是“host:port:sid”

答案 2 :(得分:1)

应该是

String url =" JDBC:预言:瘦:@localhost:1521:XE&#34 ;;

答案 3 :(得分:0)

在连接字符串中添加数据库SID

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

答案 4 :(得分:0)

你的SID可能是XE,所以它应该是jdbc:oracle:thin:Localhost:1521:XE

答案 5 :(得分:0)

我有同样的问题,同样的错误:

java.sql.SQLException: Io exception: Invalid connection string format, a valid format is: "host:port:sid"

我通过更新JDBC驱动程序解决了它。在我的特定情况下,从ojdbc7.jar到ojdbc8-12.2.0.1.jar