查询分析器一点都不慢,就是用JDBC就特别慢

解决方案 »

  1.   

    我的数据源是这样配的:<resource-ref>
      <res-ref-name>jdbc/myoracle</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <init-param driver-name="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
      <init-param url="jdbc:microsoft:sqlserver://lin:1433;DatabaseName=olddao;SelectMethod=cursor"/>
      <init-param user="sa"/>
      <init-param password="lin"/>
      <init-param max-connections="20"/>
      <init-param max-idle-time="30"/>
    </resource-ref>
      

  2.   

    jsp程序:ResultSet rs=null;
    Connection conn=null;
    Statement stmt=null;
    String url="jdbc:microsoft:sqlserver://fxl:1433;DatabaseName=pubs";
    String user="sa";
    String password="";
    try{
       Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
       conn= DriverManager.getConnection(url,user,password);
       stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
       String sql="select * from sales";
       stmt.executeQuery(sql);}catch (SQLException ex){
         out.print("数据库连接错误:" + ex.getMessage());
    }
    if(conn!=null){
        stmt = conn.createStatement();
        rs = stmt.executeQuery("select * from sales");
        while(rs.next()){
    %>
    <tr>
        <td><%=rs.getString("stor_id")%></td><td><%=rs.getString("ord_num")%></td>
    </tr>                  
    <%    }
    stmt.close();
    rs.close();
    conn.close();
    }
      

  3.   

    看你的程序根本就没有用到JNDI的连接池啊?好像是context.lookup("jdbc/myoracle")吧。不知道为什么叫myoracle?