| driverClassName=" com.microsoft.jdbc.sqlserver.SQLServerDriver " url=" jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=KB_Rate""/>
</Context>
配置完成后,在DBTest目录下添加一个Test文件,如下: <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <%@ page import="javax.sql.*"%> <%@ page import="javax.naming.*"%> <% Connection conn = null; Context initCtx = new InitialContext(); if (initCtx == null) throw new Exception("不能获取Context!"); Context ctx = (Context) initCtx.lookup("java:comp/env"); Object obj = (Object) ctx.lookup("/Default_JDBC ");//获取连接池对象 javax.sql.DataSource ds = (javax.sql.DataSource) obj; //类型转换 conn = ds.getConnection(); Statement stmt = conn.createStatement(); PreparedStatement ps=conn.prepareStatement("select * from FinalOrderdata"); ResultSet rs=ps.executeQuery();
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |