当前位置: 首页 > news >正文

国内html网站欣赏wordpress发文章功能不能正常显示

国内html网站欣赏,wordpress发文章功能不能正常显示,国际贸易官方网站,wordpress防cc代码文章目录JDBC 访问数据库的步骤使用 JDBC 访问数据库的演示代码使用 PreparedStatement 对象查询插入更新删除使用 Statement 对象查询删除JDBC 访问数据库的步骤 将 jdbc 驱劢程序相关的 jar 包 copy 到 WEB-INF/lib 下在 servlet 代码当中#xff0c;使用 jdbc 访问数据库使用 jdbc 访问数据库要注意如何处理异常配置错误处理页面 使用 JDBC 访问数据库的演示代码 使用 PreparedStatement 对象 查询 public class LoadEmpServlet extends HttpServlet { public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {long id Long.parseLong(request.getParameter(id));// 访问数据库 Connection conn null; try {Class.forName(com.mysql.jdbc.Driver);conn DriverManager.getConnection(jdbc:mysql://localhost:3306/jd1109db2, root,root);PreparedStatement prep conn.prepareStatement(select * from t_emp where id ?);prep.setLong(1, id);ResultSet rst prep.executeQuery(); response.setContentType(text/ htm l;charsetutf-8); PrintWriter out response.getWriter();if (rst.next()) {String name rst.getString(name);double salary rst.getDouble(salary);int age rst.getInt(age);out.println(form actionmodify?id id methodpost);out.println(id: id br/);out.println(姓名:input namename value name /br/); out.println(薪水:input namesalary value salary /br/); out.println(年龄:input nameage value age /br/);out.println(input typesubmit value确认/);out.println( /form);out.close();} } catch (Exception e) {e.printStackTrace();throw new ServletException(e); } finally {if(conn!null) { try {conn.close();} catch (SQLException e) {e.printStackTrace(); }} }} }插入 public class AddEmpServlet extends HttpServlet {public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { //这行代码要放在 getParameter()执行之前request.setCharacterEncoding(utf-8);String name request.getParameter(name);double salary Double.parseDouble(request.getParameter(salary));int age Integer.parseInt(request.getParameter(age)); System.out.println(name: name);System.out.println(salary: salary); System.out.println(age: age);//访问数据库 Connection conn null; try {Class.forName(com.mysql.jdbc.Driver); conn DriverManager.getConnection(jdbc:mysql://localhost:3306/jd1109db2, root,root);PreparedStatement prep conn.prepareStatement(insert into t_emp(name,salary,age) values(?,?,?));prep.setString(1, name);prep.setDouble(2, salary); prep.setInt(3, age); prep.executeUpdate();response.setContentType(text/html;charsetutf-8);PrintWriter out response.getWriter(); out.println( 添加雇员成功);out.close();} catch (Exception e) {e.printStackTrace();throw new ServletException(e); } finally {if(conn!null) { try {conn.close();} catch (SQLException e) {e.printStackTrace();} }}} }更新 public class ModifyEmpServlet extends HttpServlet { public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { request.setCharacterEncoding(utf-8); long id Long.parseLong(request.getParameter(id)); String name request.getParameter(name); double salary Double.parseDouble(request.getParameter(salary));int age Integer.parseInt(request.getParameter(age));// 访问数据库Connection conn null; try {Class.forName(com.mysql.jdbc.Driver); conn DriverManager.getConnection( jdbc:mysql://localhost:3306/jd1109db2,root,root);PreparedStatement prep conn.prepareStatement(update t_emp set name?,salary?,age? where id?);prep.setString(1, name);prep.setDouble(2, salary); prep.setLong(3, age); prep.setLong(4, id); prep.executeUpdate();response.sendRedirect(list); } catch (Exception e) {e.printStackTrace();throw new ServletException(e); } finally {if(conn!nul l) { try {conn.close();} catch (SQLException e) { e.printStackTrace();}} }}} 删除 public class DelEmpServlet extends HttpServlet {public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {long id Long.parseLong(request.getParameter(id));Connection conn null;// 访问数据库try {Class.forName(com.mysql.jdbc.Driver);conn DriverManager .getConnection(jdbc:mysql://localhost:3306/jd1109db2,root,root);PreparedStatement prep conn.prepareStatement(delete from t_emp where id ?); prep.setLong(1, id);prep.executeUpdate();//重定向 response.sendRedirect(list);} catch (Exception e) { //step1 先记录日志e.printStackTrace(); //step2 抛出throw new ServletException(e); } finally {if(conn!nul l) { try {conn.close();} catch (SQLException e) { e.printStackTrace();}} }}} 使用 Statement 对象 查询 利用 JDBC 访问数据库 , 显示所有雇员信息 public class ListEmpServlet extends HttpServlet{public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {//访问数据库 Connection conn null; try {Class.forName(com.mysql.jdbc.Driver);conn DriverManager.getConnection(jdbc:mysql://localhost:3306/jd1109db2,root,root); Statement stat conn.createStatement();ResultSet rst stat.executeQuery(select * from t_emp);//使用查询得到的结果生成一个表格 response.setContentType(text/html;charsetutf-8); PrintWriter out response.getWriter(); out.println(table border1 width60% cellpadding0 cellspacing0);out.println(tr tdid/td td姓名/td td薪水/td td年龄/td/tr);while (rst.next()) {long id rst.getLong(id);String name rst.getString(name);double salary rst.getDouble(salary);int age rst.getInt(age);out.println(trtd id /tdtd name /tdtd salary /tdtd age /td/tr);}out.println( /table);out.close();} catch (Exception e) { e.printStackTrace();throw new ServletException(e);} finally { if(conn!nul l) {try {conn.close();} catch (SQLException e) {e.printStackTrace(); }} }}} 删除 待续
http://www.pierceye.com/news/226918/

相关文章:

  • 建设工程项目管理网站上海it公司
  • 网站运营需要 做哪些工作做网站需要了解的知识
  • 旅游去过的地方可做标识网站百度一下网页入口
  • 做ps找图的网站有哪些法与家国建设征文网站
  • 途途外贸企业网站管理系统aspnet网站模板
  • 网站建设企业网站常用参数
  • 深圳市建设工程质量检测网站网站建设公司 待遇
  • 站长工具大全php做在线直播网站
  • 品牌建设网站公司排名3d模型代做网站
  • 保定网站建设模板联系方式网站设计时图片怎么做
  • 网站策划书内容鄂尔多斯网站制作 建设
  • 广州展厅设计公司排名seo快速排名首页
  • 网站命名方式潍坊市建设工程管理处网站
  • 暴利产品竞价单页网站上海做网站建设的公司排名
  • 坪地网站建设如何做网站前端多少钱
  • 国内用不了的网站展示图片的网站模板
  • 网站优化首页付款网站制作职业
  • 做网站的软件有些什么建设公司门户网站
  • 浙江省长兴县建设局网站自己专业做网站
  • 做网站外包最牛的公司东莞网站制作十年乐云seo
  • 慈溪专业做网站公司网站后台内容更换怎么做
  • wordpress网站搭建教程视频网站优化前景
  • 门户网站的优点seo月薪
  • 怎样做网站静态什么网站做二维码比较好
  • 共享虚拟主机做网站够用么抖音短剧推广怎么做
  • 个人网站备案内容写什么西部数码网站管理助手v3.1
  • 搜索引擎 网站模板wordpress 图片走cdn
  • 常见cms网站源码下载重庆微信网站开发公司
  • 网站开发用什么电脑天津室内设计公司排名
  • 云南网站建设招商建设公司网站计入哪个科目