鍦╟onf/server.xml涓緗涓嬶細
聽聽聽聽聽聽聽 <Context
聽聽聽聽聽聽聽聽聽聽聽 docBase="D:/myjsp"
聽聽聽聽聽聽聽聽聽聽聽 path="/myjsp">
聽聽聽聽聽聽聽聽聽 <ResourceLink
聽聽聽聽聽聽聽聽聽聽聽 global="jdbc/mysql"
聽聽聽聽聽聽聽聽聽聽聽 name="jdbc/mysql"
聽聽聽聽聽聽聽聽聽聽聽 type="javax.sql.DataSourcer"/>
聽聽聽聽聽聽聽 </Context>
:::::::::鎺ョ潃鍙互浣跨敤浜?:::::::
<%@ page contentType="text/html; charset=GBK" language="java"聽 errorPage="" %>
<%@ page session="false"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>鏃犳爣棰樻枃妗?lt;/title>
</head>
<body>
<%
/** statment搴旂敤瀹炰緥
Connection conn=null;
Statement sm=null;
ResultSet rs=null;
try
{
聽聽 InitialContext ctx=new InitialContext();
聽聽 DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
聽聽 conn=ds.getConnection();
聽聽 sm=conn.createStatement();
聽聽 rs=sm.executeQuery("select * from go");聽聽
聽聽 while(rs.next())
聽聽 {
聽聽聽聽聽 out.println(rs.getString(2)+"....."+rs.getInt("id")+"</br>");
聽聽聽 }
}catch(Exception e){
聽聽 e.printStackTrace();
}finally{
聽if(sm!=null)
聽{
聽聽sm.close();
聽}聽
聽if(conn!=null){
聽聽conn.close();
聽}
}
*/
/**preparestatement搴旂敤瀹炰緥
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
Connection conn=ds.getConnection();
PreparedStatement psm=conn.prepareStatement("insert into go(name,sex) values(?,?)");
psm.setString(1,"鍗庡摜");
psm.setString(2,"鑻遍泟");
psm.executeUpdate();
psm.close();
conn.close();
out.println("鏇存柊鎴愬姛");
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
Connection conn=ds.getConnection();
PreparedStatement psm=conn.prepareStatement("update go set name=? where id=?");
psm.setString(1,"澶╀嬌");
psm.setInt(2,2);
psm.executeUpdate();
out.println("鏇存柊鎴愬姛!");
psm.close();
conn.close();
*/
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
Connection conn=ds.getConnection();
Statement sm=conn.createStatement();
ResultSet rs=sm.executeQuery("select * from go");
while(rs.next())
{
聽out.println(rs.getString(1)+"..."+rs.getString(2)+"..."+"</br>");
}
sm.close();
rs.close();
conn.close();
%>
</body>
</html>