public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String title=request.getParameter("title");
String content=request.getParameter("content");
DataSource ds=null;
try{
Context context=new InitialContext();
ds= (DataSource) context
.lookup("java:/comp/env/jdbc/mysqlds");
}catch (Exception e)
{
System.out.println("数据库连接错误");
}
try {
Connection conn = ds.getConnection();
String sql="insert into users (username,userpwd) values(?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1, title);
pstmt.setString(3, content);
int result=pstmt.executeUpdate();
System.out.println(result);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}