关于用JS向数据库写入数据的问题求大神啊
是一个获取注册人的信息的网页,把输入的姓名性别等信息写入数据库的程序,我的程序显示向数据库中添加数据成功,但是回显的时候显示不出来,自己在mysql控制台里写了一条信息,就能显示出来,我怀疑就是数据没有能成功写进数据库,但是我查了很久也不知道哪里错了。。。。。求大神指点一下代码如下
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//String path = request.getContextPath();
//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body> <%request.setCharacterEncoding("GB18030");%>
<jsp:useBean id="bean" class="beans.User" scope="page"></jsp:useBean>
<jsp:setProperty name="bean" property="*"/>
您刚才提交的信息为:<br>
姓名:<jsp:getProperty name="bean" property="username"/><br>
年龄:<jsp:getProperty name="bean" property="age"/><br>
性别:<jsp:getProperty name="bean" property="sex"/><br>
籍贯:<jsp:getProperty name="bean" property="city"/><br>
职业:<jsp:getProperty name="bean" property="career"/><br>
</body>
<%@ page language="java" %>
<%@ page import="com.mysql.cj.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
String driverName="com.mysql.cj.jdbc.Driver";
String userName="root";
String userPasswd="123456";
//数据库名
String dbName="book";
String tableName="user";
String url = "jdbc:mysql://localhost:3306/book?&useSSL=false&serverTimezone=UTC";
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
String driver = "com.mysql.cj.jdbc.Driver";
Connection conn = null;
PreparedStatement pt = null;
try{
Class.forName("com.mysql.cj.jdbc.Driver");
out.println("创建数据库驱动成功!<br>");
conn = DriverManager.getConnection(url, userName, userPasswd);
out.println("数据库连接成功!<br>");
String sql = "insert into user"
+ "(name,password,age,sex,city,career)"
+"VALUES(?,?,?,?,?,?)";
pt = conn.prepareStatement(sql);
String username = request.getParameter("username");
String password = request.getParameter("password");
String sex = request.getParameter("sex");
String city = request.getParameter("city");
String career = request.getParameter("career");
String age = request.getParameter("age");
pt.setString(1, username);
pt.setString(2, password);
pt.setString(3, age);
pt.setString(4, sex);
pt.setString(5, city);
pt.setString(6, career);
//pt.executeUpdate();
pt.close();
conn.close();
out.println("数据库中数据添加完毕!<br>");
}catch(Exception e){
out.println("无法连接数据库,请检查数据库连接是否正确!<br>");
}
%>
</html>