gpt4 book ai didi

java - sql异常错误

转载 作者:行者123 更新时间:2023-11-30 07:27:46 24 4
gpt4 key购买 nike

我正在尝试从 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;

请告诉我什么是 scott tiger..我在那里搞得一团糟..那里有哪些用户..要解锁什么以及如何解锁?谢谢..

最佳答案

你的代码

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));");

关于java - sql异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9511149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com