📄 update.java
字号:
/*********************** Update.java *********************/
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Update extends HttpServlet
{
private Connection con = null;
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:bookdb");
}
catch (ClassNotFoundException e)
{
throw new UnavailableException(this,
"Couldn't load database driver");
}
catch (SQLException e)
{
throw new UnavailableException(this,
"Couldn't get db connection");
}
}
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
String idStr, title, author, priceStr;
idStr=req.getParameter("id");
title=req.getParameter("title");
author=req.getParameter("author");
priceStr=req.getParameter("price");
/*
int id=Integer.parseInt(idStr);
float price=new Float(priceStr).floatValue();
*/
String sql="UPDATE bookTbl SET " +
"bookId=" + idStr +
", bookTitle='" + title +
"', bookAuthor='" + author +
"', bookPrice=" + priceStr +
" WHERE bookId=" + idStr + ";" ;
//
res.setContentType("text/html");
ServletOutputStream sos=res.getOutputStream();
PrintWriter out=new PrintWriter(sos,true);
out.println("<HTML><HEAD><TITLE>bookTbl update</TITLE></HEAD>");
out.println("<BODY>");
SqlResult result = new SqlResult(con, sql);
sos.println(result.toString());
sos.println("id="+idStr+" title="+title+" author="+author+
" price="+priceStr);
out.println("</BODY></HTML>");
}
public void destroy()
{
try { if (con != null) con.close(); }
catch (SQLException ignored) { }
}
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
doGet(req, res);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -