找错,关于JSP

来源:百度知道 编辑:UC知道 时间:2024/05/27 10:51:53
<%@ page contentType="text ml;charset=gbk" import="java.sql.*"%>
<html>
<body>
<center>
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String sql="";
String id = request.getParameter("id");
sql="delete from employee where id='"+id+"'";
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/factory","root","123456");
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
%>
</center>
<%
con.close();
}catch(Exception e){e.printStackTrace();}
%>
</body>

con = DriverManager.getConnection("jdbc:mysql://localhost/factory","root","123456");
要端口的,改为
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/factory","root","123456");

第二个问题,也是主要的错误原因。
删除rs = stmt.executeQuery(sql); 这句,增加上
stmt.execute(sql);
因为executeQuery是用来查询的,而不可以删除