我正在尝试从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;
和plz告诉我什么是斯科特老虎。谢谢
您的代码
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));");