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连接

解决方案 »

  1.   

    SQLException异常,是运行sql语句发生异常
    ResultSet rset = stmt.executeQuery("select 'Hello World' from dual");???这个sql语句何解,有这种用法吗,改成下面这句试试
    ResultSet rset = stmt.executeQuery("select fieldname from dual where fieldname='Hello World'");//fieldname是字段名
      

  2.   

    select 'Hello World' from dual是绝对没有问题,我在sqlplus里也没有问题
    而且我建了一个表,再查询那个表,也是出现同样的错误。
      

  3.   

    楼上的好象说的没错,你可以在你的程序连接后边加调试信息
    比如System.out.println("连接成功");在ResultSet rset = stmt.executeQuery("select 'Hello World' from dual");后边再加System.out.println("执行成功");这样你就知道你的异常是从哪出来的了.不过你的那句SQL语句真的好差劲回去好好看看.
      

  4.   

    Connection refused从这个看是你的连接被拒绝了 看看,有什么设置不对,比如用户权限够吗
      

  5.   

    出现新的错误
    当查询select sysdate from dual时,可以得出正确的结果
    而查其他时select 'hello word' from dual时就出现以下错误。
    java.sql.SQLException: ORA-00600: internal error code, arguments: [ttcgcshnd-1], [0], [], [], [], [], [], []
      

  6.   

    是ORACLE版本的问题。你的ORACLE是不是9i的,而oracle的jdbc驱动还是8i的呢?我刚刚也是遇到同样的问题,你把\oracle\ora92\jdbc\lib下的classes12.jar替换原来的jdbc驱动就可以解决问题了
      

  7.   

    TNS-12505 TNS:listener could not resolve SID given in connect descriptor
    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.