import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class oraclethin{
public static void main(String args[]) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.0.1:1521:orcl", "system", "manager");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rset = stmt.executeQuery("select 'Hello World' from dual");
while (rset.next())
System.out.println(rset.getString(1));
rset.close();
stmt.close();
conn.close();
} catch (Exception e) {System.out.println(e.toString()); }
}
}
编译是通过
运行是出现错误:
java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))连接oracle服务器正常,我可以用sqlplus连接
import java.io.*;
import oracle.jdbc.driver.*;
class oraclethin{
public static void main(String args[]) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.0.1:1521:orcl", "system", "manager");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rset = stmt.executeQuery("select 'Hello World' from dual");
while (rset.next())
System.out.println(rset.getString(1));
rset.close();
stmt.close();
conn.close();
} catch (Exception e) {System.out.println(e.toString()); }
}
}
编译是通过
运行是出现错误:
java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))连接oracle服务器正常,我可以用sqlplus连接
ResultSet rset = stmt.executeQuery("select 'Hello World' from dual");???这个sql语句何解,有这种用法吗,改成下面这句试试
ResultSet rset = stmt.executeQuery("select fieldname from dual where fieldname='Hello World'");//fieldname是字段名
而且我建了一个表,再查询那个表,也是出现同样的错误。
比如System.out.println("连接成功");在ResultSet rset = stmt.executeQuery("select 'Hello World' from dual");后边再加System.out.println("执行成功");这样你就知道你的异常是从哪出来的了.不过你的那句SQL语句真的好差劲回去好好看看.
当查询select sysdate from dual时,可以得出正确的结果
而查其他时select 'hello word' from dual时就出现以下错误。
java.sql.SQLException: ORA-00600: internal error code, arguments: [ttcgcshnd-1], [0], [], [], [], [], [], []
Cause: The SID in CONNECT_DATA was not found in the listener's tables. Action: Check to make sure that the SID specified is correct. The SIDs that are currently registered with the listener can be obtained by typing "LSNRCTL SERVICES listener_name". These SIDs correspond to SID_NAMEs in TNSNAMES.ORA, or DB_NAMES in the INIT.ORA file.