struts下:
struts-config.xml:
   <data-sources>
    <data-source key="dataSource">
      <set-property value="false" property="autoCommit" />
      <set-property value="Example Data Source Configuration" property="description" />
      <set-property value="oracle.jdbc.driver.OracleDriver" property="driverClass" />
      <set-property value="10" property="maxCount" />
      <set-property value="2" property="minCount" />
      <set-property value="jdbc:oracle:thin:@210.29.175.252:1521:account" property="url" />
      <set-property value="temp" property="password" />
      <set-property value="temp" property="user" />
    </data-source>
  </data-sources>action:DataSource dataSource=servlet.findDataSource("dataSource"); 
Connection conn = dataSource.getConnection();
String sSQLHOMEWORK = "SELECT * FROM testtable";
PreparedStatement ps = conn.prepareStatement(sSQLHOMEWORK);
ps.setString(1,user.get(0).toString());//把?参数加进来
ResultSet sqlRst = ps.executeQuery();

解决方案 »

  1.   

    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    String url = "jdbc:oracle:thin:@localhost:1521:testdata"; //testdata为数据库的SID
    String user = "test";
    String password = "test";
    conn = DriverManager.getConnection(url, user, password);
      

  2.   

    一般的:
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    String url="jdbcracle:thin:@192.168.2.4:1521:
    oracle9";
    //orcl为你的数据库的SID
    String user="scott";
    String password="tiger";
    //String col1;
    //String col2;
    Connection conn= DriverManager.getConnection(url,user,password);
    }
    catch(ClassNotFoundException e)
    {
    throw new UnavailableException("jdbc driver not foune:"+jdbcDriver);
    }
    Statement stmt=conn.createStatement();
    String sql="select * from test";
    ResultSet rs=stmt.executeQuery(sql);
      

  3.   

    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
    String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID 
    String user="test"; 
    String password="test"; 
    Connection conn= DriverManager.getConnection(url,user,password);