JSP+java开发

时间:2016-06-01 13:10:25
【文件属性】:

文件名称:JSP+java开发

文件大小:3KB

文件格式:JSP

更新时间:2016-06-01 13:10:25

JSP ,java 网页设计

实现向数据库添加数据。其主要的代码是: <% boolean flag = false; Login ck2 = new Login(); request.setCharacterEncoding("UTF-8"); String num = request.getParameter("num"); String password = request.getParameter("password"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String age = request.getParameter("age"); String tel = request.getParameter("num"); String dept = request.getParameter("dept"); String address = request.getParameter("address"); flag = ck2.Logincheck(num, password); System.out.println(flag); if (!flag) { String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";// 驱动类 String url = "jdbc:sqlserver://localhost:1433;DatabaseName=users"; // 连接数据库的地址 String user = "sa";// 数据库用户名 String pwd = "123";// 数据库密码 Connection ct = null; PreparedStatement ps = null; ResultSet rs = null; Class.forName(driver);// 加载驱动程序,实例化 ct = DriverManager.getConnection(url, user, pwd);// 创建一个连接 //sql=insert into admins('num','name','sex','age','tel','password') String sql = "insert into admins(num,password,name,sex,age,tel,dept,address)" + "values('" + num + "','" + password + "','" + name + "','" + sex + "','" + age + "','" + tel + "','" + dept + "','" + address + "' )"; System.out.println(sql); ps = ct.prepareStatement(sql); ps.execute(); ct.close(); response.sendRedirect("denglu.jsp"); } else { System.out.print("注册失败 "); response.sendRedirect("zhuce.jsp"); } %>


网友评论