jsp-mysql 帮我看看ResultSet rs = stmt.executeUpdate这句是什么问题。。
<%@pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%><%Stringpath=reques...
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'insert.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>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String name = request.getParameter("name");
System.out.println(name);
String address = request.getParameter("address");
String sex = request.getParameter("sex");
String phone = request.getParameter("phone");
Class.forName("com.mysql.jdbc.Driver");
java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String user = "root";
String password = "1234";
String dburl ;
dburl = "jdbc:mysql://localhost:3306/mysql";
Connection con = java.sql.DriverManager.getConnection(dburl,user,password);
Statement stmt = con.createStatement();
String sql=" SELECT * FROM mysql.377";
ResultSet rs = stmt.executeUpdate("insert into mysql.377 (id,name,sex,address,phone)values("+id+",'"+name+"','"+sex+"','"+address+"','"+phone+"')");
%>
<center>
<%
if(rs.next())
{
out.print("<br><h3>成功输入!</h3>");
}
else{
out.print("<br><h3>输入失败!</h3>");
}
%>
<br>
<a href=information-input.jsp>返回信息输入页面</a> <a href=chaxun.jsp>进入信息查询页面</a>
</center>
<%
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(con!=null)
{
con.close();
}
%>
</body>
</html> 展开
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'insert.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>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String name = request.getParameter("name");
System.out.println(name);
String address = request.getParameter("address");
String sex = request.getParameter("sex");
String phone = request.getParameter("phone");
Class.forName("com.mysql.jdbc.Driver");
java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String user = "root";
String password = "1234";
String dburl ;
dburl = "jdbc:mysql://localhost:3306/mysql";
Connection con = java.sql.DriverManager.getConnection(dburl,user,password);
Statement stmt = con.createStatement();
String sql=" SELECT * FROM mysql.377";
ResultSet rs = stmt.executeUpdate("insert into mysql.377 (id,name,sex,address,phone)values("+id+",'"+name+"','"+sex+"','"+address+"','"+phone+"')");
%>
<center>
<%
if(rs.next())
{
out.print("<br><h3>成功输入!</h3>");
}
else{
out.print("<br><h3>输入失败!</h3>");
}
%>
<br>
<a href=information-input.jsp>返回信息输入页面</a> <a href=chaxun.jsp>进入信息查询页面</a>
</center>
<%
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(con!=null)
{
con.close();
}
%>
</body>
</html> 展开
1个回答
展开全部
你的id是什么id,是自增的吗?
如果是,就不需要再给id加值了!
(' ','"+name+"','"+sex+"','"+address+"','"+phone+"')");
如果不是
(' "+id+" ' ,'"+name+"','"+sex+"','"+address+"','"+phone+"')");
如果是,就不需要再给id加值了!
(' ','"+name+"','"+sex+"','"+address+"','"+phone+"')");
如果不是
(' "+id+" ' ,'"+name+"','"+sex+"','"+address+"','"+phone+"')");
更多追问追答
追问
Type mismatch: cannot convert from int to ResultSet
Connection con = java.sql.DriverManager.getConnection(dburl,user,password);
ResultSet rs = stmt.executeUpdate("insert into mysql.377 (id,name,sex,address,phone)values(' "+id+"','"+name+"','"+sex+"','"+address+"','"+phone+"')");
53: %>
id是这里的 学号:
追答
你这是更新数据,不是查询数据,把结果集去掉.更新数据,没有返回结果集!
直接这个:
stmt.executeUpdate("insert into mysql.377 values(' "+id+" ','"+name+"','"+sex+"','"+address+"','"+phone+"')");
改称这个.看你的id号好像没有单引号
单引号和双引号中间没空格!为了看的清晰,才打的空格
-------------------------------------------------------------------------
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询