<context-param>
<param-name>javax.servlet.jsp.jstl.sql.dataSource</param-name>
<param-value>jdbc:mysql://localhost:3306/testDB,com.mysql.jdbc.Driver,root,1234</param-value>
</context-param>就只配置了web.xml 将来部署的时候整个应用Copy过去tomcat就可以了吧。但是数据源的访问代码怎么写?

解决方案 »

  1.   

    你的配置与问题吧,JNDI名都没有,你如何去找找.
      

  2.   

    我的例子,参老一下
    String jndi_name="java:comp/env/jdbc/DBTest"; 
    String select_user_sql="select * from customer"; Context ctx = new InitialContext(); 
    if(ctx == null ) 
    throw new Exception("No Context");DataSource ds = (DataSource)ctx.lookup(jndi_name); Connection conn = ds.getConnection();
    try { 
    PreparedStatement psPreparedStatement=conn.prepareStatement(select_user_sql); 
    ResultSet resultSet = psPreparedStatement.executeQuery(); 
    while(resultSet.next()){ 
      //System.out.println("s");  
      out.println(resultSet.getString("CID"));
      out.print(resultSet.getString("username"));
      out.print(resultSet.getString("password"));
      out.println();

    }catch(SQLException e) { 
    e.printStackTrace(); 
    }finally { 
    conn.close(); 
    }