jsp页面连接MySql数据库
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%@pageimport="java.s...
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'inster.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Connection conn = null;
Statement stat = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/blog", user = "root", password = "sys";
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
String sql = "insert into rht (name,password) values=('jj','1234')";
if (stat.executeUpdate(sql) == 1)
out.print("数据插入成功");
else
out.print("数据插入失败");
if (stat != null) {
stat.close();
}
if (conn != null) {
conn.close();
}
%>
</body>
</html>
报如下错误,请各位大侠帮看看错那了,在此谢谢了!!
严重: Servlet.service() for servlet jsp threw exception
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=('jj','1234')' at line 1 展开
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'inster.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Connection conn = null;
Statement stat = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/blog", user = "root", password = "sys";
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
String sql = "insert into rht (name,password) values=('jj','1234')";
if (stat.executeUpdate(sql) == 1)
out.print("数据插入成功");
else
out.print("数据插入失败");
if (stat != null) {
stat.close();
}
if (conn != null) {
conn.close();
}
%>
</body>
</html>
报如下错误,请各位大侠帮看看错那了,在此谢谢了!!
严重: Servlet.service() for servlet jsp threw exception
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=('jj','1234')' at line 1 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询