import java.sql.*; 
import oracle.jdbc.*;  //oracle的jdbc驱动程序public class jdbctest { 
  public static void main (String args []) throws SQLException { 
    // Load Oracle driver
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
     
    // Connect to the local database
    Connection conn = 
 DriverManager.getConnection ("jdbc:oracle:dnldthin:@<jc_pdm>:<1526>:<jcpdm>", "new_pdm", "pdm");    // Query the employee names 
    Statement stmt = conn.createStatement (); 
    ResultSet rset = stmt.executeQuery ("select * from membinfo");      // Print the name out 
    while (rset.next ())
      System.out.println (rset.getString (1));
  } 

错误是:指定了无效的ORACLE URL

解决方案 »

  1.   

    ("jdbc:oracle:dnldthin:@<jc_pdm>:<1526>:<jcpdm>", 错了

    ("jdbc:oracle:dnldthin:@126.1.1.1:1521:jcpdm", 
      

  2.   

    如下可用:
    jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=XXX.XXX.XXX.XXX)(PROTOCOL=tcp)(PORT=1521))(CONNECT_DATA=(SID=YOUR SID)))
      

  3.   

    多谢两位指点,只是用你们的写法还是错误。
    用radish的错误是指定了无效的ORACLE URL
    用leonqin(清凉)的错误是:指定了无法解析的连接
      

  4.   

    多谢两位指点,只是用你们的写法还是错误。
    用radish的错误是指定了无效的ORACLE URL
    用leonqin(清凉)的错误是:指定了无法解析的连接
      

  5.   

    jdbc:oracle:thin:@126.1.1.1:1521:jcpdm试试这个。
      

  6.   

    你用的是什么OS?在linux下是lsnrctl start。
    下面是oracle的一个jdbc实例程序,希望对你有帮助:
    /**
     * @author  Reghu
     * @version 1.0
     *
     * Development Environment        :  JDeveloper 2.0
     * Name of the Application        :  SingleConnectionSample.java
     * Creation/Modification History  :
     *
     *    rkrishna.in       17-Dec-1998      Created
     *
     * Overview of Application        :
     *
     * The GUI for this application is handled in SingleConnectionFrame.java 
     *
     * This sample connects to a database instance using JDBC-Thin Driver.
     * The result of the connection attempt will display in a results text area.
     * Connection status and errors, if any are displayed in the status bar.
     *
     */
    import java.sql.*; //Package for JDBC classes.public class SingleConnectionSample {
      //Database Connection Object
      Connection  m_connection = null;  //GUI handler for this sample
      //SingleConnectionFrame  m_GUI; /**
     *  Constructor , instantiates GUI.
     **/
     public SingleConnectionSample(){
        m_GUI = new SingleConnectionFrame(this); //Instantiate GUI
        m_GUI.setVisible(true);
     } /**
     *  Main entry point for the class. Instantiates the SingleConnectionSample
     *  class and sets up the database connection.
     **/
     public static void main(String args[]){
       //Instantiate SingleConnectionSample class
       SingleConnectionSample SingleCon = new SingleConnectionSample();
       SingleCon.dbConnection();//Sets up DB connection
     } /**
     *  Dispatches the GUI events to the appropriate method, which performs
     *  the required operations. This method is invoked when event occurs in the GUI
     *  (like Button clicks ). This method is invoked from the setupListeners method
     *  of SingleConnectionFrame.java
     **/
     public void dispatchEvent(String p_eventName) {
       if(p_eventName.equals("EXIT")) //Dispatch Event
          exitApplication(); } /**
     *  Creates a database connection object using JDBC. Please substitute the
     *  database connection parameters with appropriate values in
     *  ConnectionParams.java
     **/
     public void dbConnection(){
       try {
           m_GUI.putStatus("Trying to connect to the Database");       //Load the Oracle JDBC Driver and register it.
           DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());       //Form the database connect string(TNSNAMES entry) as a name-value pair
           //using the connection parameters as specified in ConnectionParams.java
           String l_dbConnectString =    ××××注意这里!!!!!!××××
                "(DESCRIPTION=(ADDRESS=(HOST="+ConnectionParams.s_hostName+")"+
                "(PROTOCOL=tcp)(PORT="+ConnectionParams.s_portNumber+"))"+
                "(CONNECT_DATA=(SID="+ConnectionParams.s_databaseSID+")))";       //The following statement creates a database connection object
           //using the DriverManager.getConnection method. The first parameter is
           //the database URL which is constructed based on the connection
           //parameters specified in ConnectionParams.java.
           //The URL syntax is as follows:
           //"jdbc:oracle:<driver>:@<db connection string>"
           //<driver>, can be 'thin' or 'oci8'
           //<db connect string>, is a Net8 name-value, denoting the TNSNAMES entry
           m_connection = DriverManager.getConnection(
                           "jdbc:oracle:thin:@"+l_dbConnectString,
                           ConnectionParams.s_userName,ConnectionParams.s_password);       //Sets the auto-commit property as false. By default it is true.
           m_connection.setAutoCommit(false);       m_GUI.appendStatusLn("...Connected");
           m_GUI.putResults("Successful connection as user " +
                            ConnectionParams.s_userName +" to database "
                             +ConnectionParams.s_databaseSID );
       } catch(Exception ex){ //Trap SQL errors
            m_GUI.appendStatusLn("...Not connected");
            m_GUI.appendStatus("Error in connecting to the "+
                                ConnectionParams.s_databaseSID+" Database with user"
                                +" name "+ConnectionParams.s_userName+ '\n'
                                +ex.toString());
            m_GUI.putResults("Unsuccessful connection when user name "+
                              ConnectionParams.s_userName+" attempts connection to "
                              +ConnectionParams.s_databaseSID);
       }
     } /**
     *  Closing the Database Connection Object and exit the application
     **/
     public void exitApplication() {
       try {
           m_GUI.putStatus("Closing the connection....please wait.....");
           if(m_connection != null)
              m_connection.close(); //Closing the m_connection object.
       } catch(SQLException ex){ //Trap SQLException
          m_GUI.putStatus(ex.toString());
       }
       System.exit(0); //Exit the aplication
     }
    }
      

  7.   

    你用的是什么OS?在linux下是lsnrctl start。
    下面是oracle的一个jdbc实例程序,希望对你有帮助:
    /**
     * @author  Reghu
     * @version 1.0
     *
     * Development Environment        :  JDeveloper 2.0
     * Name of the Application        :  SingleConnectionSample.java
     * Creation/Modification History  :
     *
     *    rkrishna.in       17-Dec-1998      Created
     *
     * Overview of Application        :
     *
     * The GUI for this application is handled in SingleConnectionFrame.java 
     *
     * This sample connects to a database instance using JDBC-Thin Driver.
     * The result of the connection attempt will display in a results text area.
     * Connection status and errors, if any are displayed in the status bar.
     *
     */
    import java.sql.*; //Package for JDBC classes.public class SingleConnectionSample {
      //Database Connection Object
      Connection  m_connection = null;  //GUI handler for this sample
      //SingleConnectionFrame  m_GUI; /**
     *  Constructor , instantiates GUI.
     **/
     public SingleConnectionSample(){
        m_GUI = new SingleConnectionFrame(this); //Instantiate GUI
        m_GUI.setVisible(true);
     } /**
     *  Main entry point for the class. Instantiates the SingleConnectionSample
     *  class and sets up the database connection.
     **/
     public static void main(String args[]){
       //Instantiate SingleConnectionSample class
       SingleConnectionSample SingleCon = new SingleConnectionSample();
       SingleCon.dbConnection();//Sets up DB connection
     } /**
     *  Dispatches the GUI events to the appropriate method, which performs
     *  the required operations. This method is invoked when event occurs in the GUI
     *  (like Button clicks ). This method is invoked from the setupListeners method
     *  of SingleConnectionFrame.java
     **/
     public void dispatchEvent(String p_eventName) {
       if(p_eventName.equals("EXIT")) //Dispatch Event
          exitApplication(); } /**
     *  Creates a database connection object using JDBC. Please substitute the
     *  database connection parameters with appropriate values in
     *  ConnectionParams.java
     **/
     public void dbConnection(){
       try {
           m_GUI.putStatus("Trying to connect to the Database");       //Load the Oracle JDBC Driver and register it.
           DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());       //Form the database connect string(TNSNAMES entry) as a name-value pair
           //using the connection parameters as specified in ConnectionParams.java
           String l_dbConnectString =    ××××注意这里!!!!!!××××
                "(DESCRIPTION=(ADDRESS=(HOST="+ConnectionParams.s_hostName+")"+
                "(PROTOCOL=tcp)(PORT="+ConnectionParams.s_portNumber+"))"+
                "(CONNECT_DATA=(SID="+ConnectionParams.s_databaseSID+")))";       //The following statement creates a database connection object
           //using the DriverManager.getConnection method. The first parameter is
           //the database URL which is constructed based on the connection
           //parameters specified in ConnectionParams.java.
           //The URL syntax is as follows:
           //"jdbc:oracle:<driver>:@<db connection string>"
           //<driver>, can be 'thin' or 'oci8'
           //<db connect string>, is a Net8 name-value, denoting the TNSNAMES entry
           m_connection = DriverManager.getConnection(
                           "jdbc:oracle:thin:@"+l_dbConnectString,
                           ConnectionParams.s_userName,ConnectionParams.s_password);       //Sets the auto-commit property as false. By default it is true.
           m_connection.setAutoCommit(false);       m_GUI.appendStatusLn("...Connected");
           m_GUI.putResults("Successful connection as user " +
                            ConnectionParams.s_userName +" to database "
                             +ConnectionParams.s_databaseSID );
       } catch(Exception ex){ //Trap SQL errors
            m_GUI.appendStatusLn("...Not connected");
            m_GUI.appendStatus("Error in connecting to the "+
                                ConnectionParams.s_databaseSID+" Database with user"
                                +" name "+ConnectionParams.s_userName+ '\n'
                                +ex.toString());
            m_GUI.putResults("Unsuccessful connection when user name "+
                              ConnectionParams.s_userName+" attempts connection to "
                              +ConnectionParams.s_databaseSID);
       }
     } /**
     *  Closing the Database Connection Object and exit the application
     **/
     public void exitApplication() {
       try {
           m_GUI.putStatus("Closing the connection....please wait.....");
           if(m_connection != null)
              m_connection.close(); //Closing the m_connection object.
       } catch(SQLException ex){ //Trap SQLException
          m_GUI.putStatus(ex.toString());
       }
       System.exit(0); //Exit the aplication
     }
    }
      

  8.   

    好像上面这个程序是用JDeveloper开发的,不知道哪位用过没有?我觉得可能用它开发就好多了。 ;)毕竟会使用工具是人类的最大优点啊! HOHO我下了一个Jdeveloper3.0 200多MB。但是好像只支持win2000/nt ;( 我的notebook上只有win me 不知道能不能用。