panchenxiao
2018-06-21 11:35
采纳率: 100%
浏览 797

新手关于jsp页面连接数据库的问题

小弟想用jsp文件输入数据到mysql数据库中
这是代码
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="com.mysql.jdbc.*,java.sql.Connection, java.sql.DriverManager,java.sql.PreparedStatement,java.sql.ResultSet " %>


<%
Class.forName("com.mysql.cj.jdbc.Driver"); //加载驱动
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=true","root","123456");//创建连接

String username = request.getParameter("user") ;
String password = request.getParameter("password") ;
String sql = "insert into users(username , password) values('"+username+"','"+password+"')";
out.print("
"+password+"
");
PreparedStatement user = connection.preparedStatement(sql);
user.executeUpdate();
%>


这是报错信息
An error occurred at line: [13] in the jsp file: [/zhuce.jsp]
connection cannot be resolved
10: String password = request.getParameter("password") ;
11: String sql = "insert into users(username , password) values('"+username+"','"+password+"')";
12: out.print("
"+password+"
");
13: PreparedStatement user = connection.preparedStatement(sql);
14: user.executeUpdate();
15: %>
16:

8条回答 默认 最新

相关推荐 更多相似问题