|
public class addTextToMysql extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
response.setContentType("text/html;charset=gb2312");
PrintWriter outToClient=response.getWriter();
Connection conn=null;
ResultSet rs=null;
try{
dbConn myconn=new dbConn();
conn=myconn.getConn();
PreparedStatement pstmt=conn.prepareStatement("insert into table_1 values(?,?.?)");
pstmt.setInt(1,007);
pstmt.setString(2,"zhongbin");
pstmt.setString(3,"student");
int update=pstmt.executeUpdate();
outToClient.println("<html><head><title>操作成功</title></head>");
outToClient.println("<body><font size=15>谢谢</font></body></html>");
}catch(Exception e){
outToClient.println("<html><head><title>操作失败</title></head>");
outToClient.println("<body><font size=15>sorry!!</font></body></html>");
}
} |
|