【问题标题】:sql exception errorssql异常错误
【发布时间】:2012-03-01 05:36:48
【问题描述】:

我正在尝试从 java 程序执行 sql 命令..我没有关于此代码的任何错误..但我面临来自数据库的连接拒绝..

import java.sql.*;
public class DBCreateTable
{
    public static void main(String args[]) throws Exception
    {
        DriverManager.registerDriver (new Oracle.jdbc.driver.OracleDriver());
        Connection con=DriverManager.getConnection(
              "jdbc:oracle:thin:@localhost:1521:xe","lms","abc");
        Statement stmt=con.CreateStatement();
        stmt.executeUpdate("create table emp(eno number(5),name varchar2(20))");
    }
}

遇到的错误是:

Exception in thread "main" java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599488)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
        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.<init>(OracleConnection.java:404)
       at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
va:468)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
        at java.sql.DriverManager.getConnection(DriverManager.java:579)
        at java.sql.DriverManager.getConnection(DriverManager.java:221)
        at DBCreateTable.main(DBCreateTable.java:7)

在我的 sql 命令中,我完成了以下操作..

    SQL> connect system/tiger;
    SQL> create user lms identified by abc;
    SQL> grant connect,resource to lms;

请告诉我什么是斯科特老虎..我在那里搞砸了很多..那里有什么用户..要解锁什么以及如何解锁?谢谢。。

【问题讨论】:

    标签: java sql jdbc


    【解决方案1】:

    你的代码

    Connection con=DriverManager.getConnection(
              "jdbc:oracle:thin:@localhost:1521:xe","lms","abc");
    

    改成

    Connection con=DriverManager.getConnection(
              "jdbc:oracle:thin:@//localhost:1521:xe","lms","abc");
    

    更多信息可以查看

    http://www.orafaq.com/wiki/JDBC
    

    需要进行其他更改

    stmt.executeUpdate("create table emp(eno number(5),name varchar2(20))");
    

    改成

    stmt.executeUpdate("create table emp(eno number(5),name varchar2(20));");
    

    【讨论】:

    • 我把它改成了你说的......我仍然得到一个错误......线程“main”中的异常java.sql.SQLException:Io异常:无效的连接字符串格式,有效的格式是: "//host:port/service_name"
    • 尝试删除@符号 Connection con=DriverManager.getConnection("jdbc:oracle:thin://localhost:1521:xe","lms","abc");
    • 仍然出现一些错误...线程“main”中的异常 java.sql.SQLException: ORA-00911: oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) 处的字符无效
    • stmt.executeUpdate("创建表 emp(eno number(5),name varchar2(20))");将此更改为 stmt.executeUpdate("create table emp(eno number(5),name varchar2(20));");
    • 是的,我第一次已经更改了它..但我仍然遇到同样的错误..我想问题出在数据库上..你能帮忙吗?
    【解决方案2】:

    您的 oracle 服务可能已停止。 scott/tiger 是 oracle 中默认的用户名密码之一。你应该在你的代码中使用你的 try/catch。

    【讨论】:

    • 如何知道我的 oracle 服务是否停止?
    • 在运行中输入“services.msc”,如果您使用的是Windows系统,您可以在此处看到您所有正在运行的服务。你可以在那里找到 oracle 服务
    【解决方案3】:

    让我们看看错误描述是怎么说的:

    >oerr ora 12505
    12505, 00000, "TNS:listener does not currently know of SID given in connect descriptor"
    // *Cause:  The listener received a request to establish a connection to a
    // database or other service. The connect descriptor received by the listener
    // specified a SID for an instance (usually a database instance) that either
    // has not yet dynamically registered with the listener or has not been
    // statically configured for the listener. This may be a temporary condition
    // such as after the listener has started, but before the database instance
    // has registered with the listener.
    // *Action:
    //  - Wait a moment and try to connect a second time.
    //  - Check which instances are currently known by the listener by executing:
    //    lsnrctl services <listener name>
    //  - Check that the SID parameter in the connect descriptor specifies
    //    an instance known by the listener.
    //  - Check for an event in the listener.log file.
    

    【讨论】:

    • 我应该如何解决这个问题
    【解决方案4】:

    另一个问题是类路径中可能有较旧的驱动程序(因此请确保在运行时类路径中没有 classes111.jar 或较旧的东西)。

    确保类路径中有正确的驱动程序(thin 或 oci)。

    【讨论】:

      【解决方案5】:

      试试这个代码:

      Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "lms", "abc");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-27
        • 2016-08-17
        • 2014-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-23
        相关资源
        最近更新 更多