<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page import="java.sql.Connection" %> <%@ page import="java.sql.DriverManager" %> <%@ page import="java.sql.SQLException" %> <%@ page import="java.sql.PreparedStatement" %> <html> <head> <title>添加结果</title> <style type="text/css"> body{ background: #d7c7e9; align-content: center; text-align: center; } </style> </head> <body> <%request.setCharacterEncoding("UTF-8");%> <jsp:useBean id="user" class="bean.Users"></jsp:useBean> <jsp:setProperty name="user" property="*"/> <% Connection conn =null; try{ try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); out.print("驱动器加载失败"); } String url = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8"; String username = "root"; String password = "123456"; try{ conn = DriverManager.getConnection(url,username,password); }catch (SQLException e){ out.println(e.getMessage()); out.println("数据库连接失败"); } if(conn != null){ String sql = "insert into user(username,password,xingming,xingbie,sheng,city,gongzuodanwei,zhuanyefangxiang,hangye,jiaoyu,zhicheng,tongxun,youzheng,shouji,gudingdianhua,qq,msn,power,zhenghao)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1,user.getUsername()); ps.setString(2,user.getPassword()); ps.setString(3,user.getXingming()); ps.setString(4,user.getXingbie()); ps.setString(5,user.getSheng()); ps.setString(6,user.getCity()); ps.setString(7,user.getGongzuodanwei()); ps.setString(8,user.getZhuanyefangxiang()); ps.setString(9,user.getHangye()); ps.setString(10,user.getJiaoyu()); ps.setString(11,user.getZhicheng()); ps.setString(12,user.getTongxun()); ps.setString(13,user.getYouzheng()); ps.setString(14,user.getShouji()); ps.setString(15,user.getGudingdianhua()); ps.setString(16,user.getQq()); ps.setString(17,user.getMsn()); ps.setInt(18,user.getPower()); ps.setString(19,user.getZhenghao()); int row = ps.executeUpdate(); if(row>0){ out.println("注册成功"); } } }catch (Exception e){ e.printStackTrace(); out.print("注册失败"); } %> <br> <a href="denglu.jsp">返回</a> </body> </html>
对于hbase的测试使用