请高手看看我这servlet 有没有问题
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>");
}
} 这个继承HttpServlet的addTextToMysql类写得看不懂 :oops:
很明显插入(007,zhongbin,student)到表table_1应该是pstmt.executeInsert()吧(我是凭ADODB的API的感觉)怎么是pstmt.executeUpdate();更新操作呢?
请楼主使用 BBCODE来发代码贴
页:
[1]