drivers=oracle.jdbc.driver.OracleDriver
jdbcurl=jdbc:oracle:thin:@192.168.9.22:1521:orcl
username=system
password=manager

解决方案 »

  1.   

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver);;
    DriverManager.getConnection(url, username, pwd);
      

  2.   

    to nunu(尼克) :
    我在使用
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    时说找不到oracledriver().
      

  3.   

    我仍在等::
    我把下载的oracle 9i的jdbc 驱动classes12.zip 压成classes12.jar
    并放在d:\jdk\lib目录下,然后把类路径
    set classpath=%classpath%;d:\jdk\lib\classes12.jar
    不过,编译没问题,运行时还是报错import java.sql.*;
    import oracle.jdbc.*;
    import oracle.jdbc.driver.*;
    class Employee
    {
      public static void main (String args [])
           throws SQLException
      {
        // Load the Oracle JDBC driver
        DriverManager.registerDriver(new OracleDriver());    // Connect to the database
        // You must put a database name after the @ sign in the connection URL.
        // You can use either the fully specified SQL*net syntax or a short cut
        // syntax as <host>:<port>:<sid>.  The example uses the short cut syntax.
        Connection conn =
          DriverManager.getConnection ("jdbc:oracle:thin:@foxconncsu:1521:hotmail",
       "scott", "tiger");    // Create a Statement
        Statement stmt = conn.createStatement ();    // Select the ENAME column from the EMP table
        ResultSet rset = stmt.executeQuery ("select ENAME from EMP");    // Iterate through the result and print the employee names
        while (rset.next ())
          System.out.println (rset.getString (1));
      }
    }
      

  4.   

    报什么错.另外,你的程序用完资源之后要关闭rset.close();
    stmt.close();
    conn.close();关闭资源是个好习惯,很重要
      

  5.   

    "我把下载的oracle 9i的jdbc 驱动classes12.zip 压成classes12.jar"不用再压了,直接用就行了set classpath=%classpath%;d:\jdk\lib\classes12.zip
      

  6.   

    不需要!
    首先你不该把下载的CLASSES12.zip压缩成JAR,然后在CLASSPTH中直接加入:set classpath=%classpath%;d:\jdk\lib\classes12.zip
    这下就应该可以了!
      

  7.   

    现在程序编译通过,
    运行后
    Io 异常: The Network Adapter could not establish the connectionException
    n thread "main" java.lang.NullPointerException
          at conndb.main(conndb.java:36)能解释下怎么回事吗???
      

  8.   

    rset.close();
    stmt.close();
    conn.close();
      

  9.   

    将你的驱动程序包放在与代码相同的目录下,系统的ClassPath不用管它
    String strDriver = "oracle.jdbc.driver.OracleDriver";
    String strService = "jdbc:oracle:thin:@服务器IP:端口:服务名";
    String strUserID = "用户名";
    String strPassword = "密码";
    Class.forName(strDriver).newInstance();
    m_connection = (Connection)DriverManager.getConnection(strService, strUserID, strPassword);
      

  10.   

    你的CONNECTION对象即conndb没有正确连接上,你仔细检查一下!
    把代码拿上来看看!
      

  11.   

    代码如下:import java.sql.*;public class conndb
    {
      public static void main (String args [])
           throws SQLException
      {
        // Load the Oracle JDBC driver
        try{
         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        }catch(SQLException ex){
        System.err.print("aaaaaaaaaaa" + ex.getMessage());
        }
        // Connect to the database
        Connection conn=null;
        Statement stmt=null;
        try{
         conn =DriverManager.getConnection ("jdbc:oracle:thin:@10.134.11.66:1521:hotmail",
       "pdm", "tartan");}
       catch(SQLException ex){
        System.err.print("dddddddd" + ex.getMessage());
        }    // Create a Statement
        stmt = conn.createStatement ();    // Select the ENAME column from the EMP table
        ResultSet rset = stmt.executeQuery ("select ENAME from EMP");    // Iterate through the result and print the employee names
        while (rset.next ())
          System.out.println (rset.getString (1));
      }
    }
    运行后:
    Io 异常: The Network Adapter could not establish the connectionException
    n thread "main" java.lang.NullPointerException
          at conndb.main(conndb.java:36)
      

  12.   

    // Create a Statement
    stmt = conn.createStatement ();这句前面你最好判断一下
    conn是否为null;
    不为null的话再执行这一句。
      

  13.   

    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import javax.sql.*;
    import oracle.jdbc.pool.*;
    import javax.naming.*;
    import oracle.jdbc.driver.*;public class DBConnectionPool
    {
      private OracleConnectionCacheImpl m_DBConnectionPool;
      public DBConnectionPool()
      {
    this.createConnectionPool();    }   private void createConnectionPool() 
      {
    BufferedReader in = null;
    try
    {
    OracleConnectionPoolDataSource l_ocpds = new OracleConnectionPoolDataSource(); String path ="";
    String connstr = "";
    String user = "";
    String password = "";
        int idx = 0;

    path = System.getProperty("user.dir");
         in = new BufferedReader(new FileReader(path+"\\DBInfomation.ini"));
        
        if((connstr = in.readLine ()) != null)
        {
          idx = connstr.indexOf ("=");
          if(idx > 0)
           connstr = connstr.substring (idx + 1).trim();
          else
           connstr = "";
        }
        else
         connstr = "";
        if((user = in.readLine ()) != null)
        {
          idx = user.indexOf  ("=");
          if(idx > 0)
           user = user.substring (idx + 1).trim();
          else
           user = "";
        }
        else
         user = "";
        if((password = in.readLine ()) != null)
        {
          idx = password.indexOf  ("=");
          if(idx > 0)
           password = password.substring (idx + 1).trim();
          else
           password = "";
        }
        else
         password = ""; l_ocpds.setURL(connstr);
    l_ocpds.setUser(user); l_ocpds.setPassword(password);
    m_DBConnectionPool = new OracleConnectionCacheImpl(l_ocpds);

    m_DBConnectionPool.setMaxLimit (Parameter.iConnectionMax);

    (OracleConnectionCacheImpl.FIXED_RETURN_NULL_SCHEME);
    (OracleConnectionCacheImpl.FIXED_WAIT_SCHEME );
    m_DBConnectionPool.setCacheScheme (OracleConnectionCacheImpl.DYNAMIC_SCHEME ); if (m_DBConnectionPool != null )
    System.out.println("Connection Pool Created Succeefully");
    else
    System.out.println("Error in Creating Connection Pool");
    }
    catch(SQLException ex) 

    System.out.println( "Error in Connecting to the Database "+'\n'+ex.toString());
    }
    catch(FileNotFoundException ex)
    {
    System.out.println("user.dir is " + System.getProperty("user.dir"));
    System.out.println("java.home is " + System.getProperty("java.home"));
    System.out.println( "Error in open DBInfo.ini "+'\n'+ex.toString());
    }
    catch(IOException ex)
    {
    System.out.println( "Error in read DBInfo.ini "+'\n'+ex.toString());
    }
    finally
    {
    try
    {
    if(in!=null)
    in.close();
    }
    catch(Exception ex)
    {;}
    }
      }  public Connection getConnection()
      {
    Connection l_connection = null;
    try
    {
    if( m_DBConnectionPool != null )
    {
    l_connection = m_DBConnectionPool.getConnection();
    }
    else
    {
    System.out.println("m_DBConnectionPool is Null");
    l_connection = null;
    }
    }
    catch(SQLException ex) 

    System.out.println("Error in getting the connection "+ex.toString());
    l_connection = null;
    }
    catch(Exception ex)

    System.out.println("Error in getting the connection "+ex.toString());
    l_connection = null;
    }
    return l_connection;
      }  public void putConnection(Connection l_connection) 
      {
      if (l_connection != null)
      {
      try 
      {
      l_connection.close();   } catch (SQLException ex)
      {
     System.out.println("Error in closing the connection "+ex.toString());
      }
      }
      }
       protected void finalize() throws Throwable 
      {
     if (m_DBConnectionPool != null) 
     {
     try 
     {
     m_DBConnectionPool.close();   } 
     catch (SQLException e)
     {
    System.out.println("Error in closing the pooled connection "+e.toString());
     }
     }
      }
    }
    //DBInfomation.ini file DBConnStr=jdbc:oracle:thin:@host:number:orcl
    DBUser=1111
    DBPassword=1111
      

  14.   

    当然可以拉
        String strDriver = "oracle.jdbc.driver.OracleDriver";
    String strService = "jdbc:oracle:thin:@服务器IP:端口:服务名";
    String strUserID = "用户名";
    String strPassword = "密码";
    Class.forName(strDriver).newInstance();
    m_connection = (Connection)DriverManager.getConnection(strService, strUserID, strPassword);