public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache,must-revalidate");
response.setDateHeader("Expires", 0);
PrintWriter out = response.getWriter();
try{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/shishicaiDS");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
stmt.addBatch("create temporary table tmp(id int(4) primary key,n FLOAT,dr varchar(50))");
stmt.addBatch("insert into tmp values (1,100,'gone'), (2,2000,'xx'),(3,3000,'yy')");
stmt.addBatch("update test, tmp set test.dr=tmp.dr ,test.n = tmp.n+test.n where test.id=tmp.id");
stmt.executeBatch();
System.out.println("ok");
conn.close();
}catch(Exception e){
System.out.println(e) ;
}finally{
out.flush();
out.close();
}
}
http://www.2cto.com/kf/201108/99512.html