然后 建立 DataSource,其中JNDI名字在程序中要用到
JSP页面中代码如下:
<%
try {
javax.naming.Context context=new javax.naming.InitialContext();
javax.sql.DataSource ds=(javax.sql.DataSource) context.lookup("ORCLDI");
java.sql.Connection con=ds.getConnection();
java.sql.Statement st=con.createStatement();
java.sql.ResultSet result=st.executeQuery("select * from stu");
while(result.next()){
out.println(result.getInt(1)
+" "+result.getString(2)
+" "+result.getInt(3)
+"
");
}
} catch (javax.naming.NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>