我的程序结构是:jsp+tomcat+oracle(linux)
oracle在linux服务器上,我的程序以前一直是好的,连接没有问题,自从服务器重启一次后,就出现了java.sql.SQLException: Io exception: The Network Adapter could not establish the connection这样的问题,我可以用sqlplus连接到数据库上,但是程序却不能,请大虾指教,指出问题可能出在哪些方面!

解决方案 »

  1.   

    当你使用一个无效的连接进行查询时会出现这个问题你是否使用连接池?oracle重启后,tomcat有没有重启?把tomcat重启一下试试
      

  2.   

    我没有使用连接池,tomcat重启过,试了好多次还是不行
    我的程序一直没有改,不知道是不是oracle的设置改变了什么的,就是不清楚问题在哪里
      

  3.   

    import java.sql.*;
    public class zj_linkdb 
    {
       public Connection connection; 
       private String url=new String("jdbc:oracle:thin:@host:1521:sid");
       private String username =new String("name"); 
       private String password =new String("password"); 
       private String driver =new String("oracle.jdbc.driver.OracleDriver");
       public static void main(String[] args) 
       {
         try { 
             Class.forName(driver); 
             connection = DriverManager.getConnection(url, username, password); 
               } 
          catch ( ClassNotFoundException cnfex ) { 
             System.err.println( 
                "装载 JDBC/ODBC 驱动程序失败。" ); 
             cnfex.printStackTrace(); 
             System.exit( 1 );                   
                }       
          catch ( SQLException sqlex ) { 
             System.err.println( "don't link to db!" ); 
             sqlex.printStackTrace(); 
             System.exit( 1 );  
                } 
         }

    我把程序大概列出来了,host和sid都就不写出来了
    一连接就报错
    don't link to db!
    java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
      

  4.   

    1.可能数据库连接的listener没有运行,试试lsnrctl
    2. 把程序改成这样看看
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    String s = "jdbc:oracle:thin........";
    Connection conn = DriverManager.getConnection(s,username, password);
      

  5.   

    还有检查一下是否有防火墙阻止了连接.在服务器上执行telnet localhost the-port-number
    在客户端上执行:telnet serverhost the-port-number