⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 update.java

📁 java程序设计入门教程 书上的源代码 学习JAVA非常好的入门教材代码推荐给大家
💻 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 + -