import javax.sql.DataSource;

解决方案 »

  1.   

    你那样的编程语句是什么哪里来得,我实在是没有见过,下面是我程序中的一段连接数据库的函数:
    //------------------------------------------------------------------
    import java.sql.*;
    import oracle.jdbc.*;public ResultSet GetQuery()
           throws SQLException
        {
           DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
         String url = "jdbc:oracle:thin:@192.18.8.4:1521:ORCL";
         String userName = "SCOTT";
         String password = "TIGER";
         String SQL = "SELECT * FROM EMP";
         Connection conn = DriverManager.getConnection (url, userName, password);
         Statement cstmt = conn.createStatement();
           ResultSet rs = cstmt.executeQuery(SQL);
         return rs;
        }
    //------------------------------------------------------------------如果你还有什么疑问,再来。  :-)
      

  2.   

    他是利用Weblogic的连接池来取的,你仔细查看一下是否加入了Weblogic的相关类,否则DataSource不能引用
      

  3.   

    gdsean是对的,他只是没有引入相关的包
      

  4.   

    贴一个我写的连接池取法的类你看看有没帮助package com.eigenet.ejb;import java.sql.Connection;
    import java.util.Hashtable;import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;/**
     * 建立与数据源的连接
     * 用法ConnectionFactory.getConnection()
     * 注意:调用以后一定要close掉Connection,否则连接池会满
     */
    public class ConnectionFactory {  //该类自已的一个静态实例
      private static ConnectionFactory factorySingleton;  //存储DataSource
      private DataSource dataStore = null;  //上下文联系
      private Context ctx;  /*
       * 内部静态构造
       */
      private ConnectionFactory() throws NamingException{
      }  /*
       * 建立与数据源的连接, 目前只实用于Weblogic
       * 服务器名要在内部指定.
       */
      private Connection createConnection() throws NamingException{
        Connection conn = null;
        ctx = null;
        Hashtable ht = new Hashtable();    ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ht.put(ctx.PROVIDER_URL, "t3://172.21.70.1:7001");    if (dataStore==null) {
          try {
            ctx = new InitialContext(ht);
            dataStore = (javax.sql.DataSource)ctx.lookup("mrpSource");
          }catch (Exception e) {
            System.out.println(e.getMessage());
          }
        }    try {
          conn = dataStore.getConnection();
        }catch(Exception e) {
          e.printStackTrace();
        }
        return conn;
      }  /**
       * 获取ConnectionFactory自身的一个实例, 不存在的话,则建立一个.
       */
      public static Connection getConnection() throws NamingException{
        if (ConnectionFactory.factorySingleton == null) {
          ConnectionFactory.factorySingleton = new ConnectionFactory();
        }    return ConnectionFactory.factorySingleton.createConnection();
      }}
      

  5.   

    import oracle.jdbc.*;
    此处语句错误,提示为不能直接访问该目录oralce;cannot access directory oracle,且我在服务启动时j2ee下的config下配置相应的属性,但我并不知该这个配置是否能调入,谢谢!
      

  6.   

    编译出错,错误信息:"DB.java": Error #: 302 : cannot access class oracle.jdbc.OracleDriver; java.io.IOException: class not found: class oracle.jdbc.OracleDriver at line 30, column 48
      

  7.   

    你可以试试在
    CLASSPATH中加入:$ORACLE_HOME/jdbc/lib/classes/classes12.zip;再试试~!!  :-}
      

  8.   

    我在\控制面板\系统中编辑Classpath中增加路径为D:\j2sdkee\lib\system\classes12.zip但还是不对
    错误如下,请予回答,本人急于解决此问题,谢谢!
    "DB.java": Error #: 704 : cannot access directory oracle\jdbc at line 8, column 1
    "DB.java": Error #: 302 : cannot access class oracle.jdbc.OracleDriver; java.io.IOException: class not found: class oracle.jdbc.OracleDriver at line 34, column 48
    "DB.java": Error #: 300 : variable conn not found in class DB.DB at line 38, column 7
    "DB.java": Error #: 300 : variable conn not found in class DB.DB at line 39, column 23
      

  9.   

    classes12.zip是oracle的,怎么到D:\j2sdkee\lib\system下面了,你这些错误是J2sdk报的错误嘛?再问一下,你的开发环境和运行环境是什么?
      

  10.   

    Oracle816客户端程序:http://10.141.185.185/web/sheepblack/study/oracle/oracle816classes12b.zip
    连接方法范例:
    import java.sql.*;class Employee
    {
      public static void main (String args [])
           throws SQLException, ClassNotFoundException
      {
        // Load the Oracle JDBC driver
        Class.forName ("oracle.jdbc.driver.OracleDriver");    // Connect to the database
        // You can put a database name after the @ sign in the connection URL.
        Connection conn =
          DriverManager.getConnection ("jdbc:oracle:oci8:@", "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));
      }
    }
      

  11.   

    Oracle816客户端程序:http://10.141.185.185/web/sheepblack/study/oracle/oracle816classes12b.zip
    连接方法范例:
    import java.sql.*;class Employee
    {
      public static void main (String args [])
           throws SQLException, ClassNotFoundException
      {
        // Load the Oracle JDBC driver
        Class.forName ("oracle.jdbc.driver.OracleDriver");    // Connect to the database
        // You can put a database name after the @ sign in the connection URL.
        Connection conn =
          DriverManager.getConnection ("jdbc:oracle:oci8:@", "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));
      }
    }
      

  12.   

    开发环境是JBUILDER 6企业版,服务器为j2ee 1.3.1
      

  13.   

    不好意思,JBUILDER 6我没有玩,我没有从事Java的图形开发,我是做Jsp的。我是用UltraEdit编程。我用过JDeveloper还可以,特别是配环境特简单。
      

  14.   

    这个是要配置J2EE里面的DATASOURCE,使用deploytool来配置。
    添加DATASOURCE,并在DATASOURCE里面说明JDBC和SERVER、PORT。
    具体做法使用一下deploytool就比较清楚了。
      

  15.   

    我觉得你干脆用Javac来编译算了。先看看是不是程序问题,如果不是程序有错,再看看是不是运行环境有问题,最后再看编辑器是否有问题。