myeclipse向Mysql更新和删除数据问题
我想更新数据库中的数据和删除指定要求的数据,我的jsp代码如下:运行后老是打印“数据库操作失败”和姓名和密码,请问我的代码有何问题,小弟先感谢了
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@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>更新和删改数据库中的数据</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><font size=2>
<table width="80%" border="1" height="156" cellpadding="0" cellspacing="0" >
<tr>
<td width="50%">姓名</td>
<td width="50%">密码</td>
</tr>
<%
Connection conn=null;
Statement stmt=null;
String sql=null;
ResultSet rs=null;
int ret;
try{
Class.forName("com.mysql.jdbc.Driver");
String strCon="jdbc:mysql//localhost:3306/test";
conn=DriverManager.getConnection(strCon,"root","root");
stmt=conn.createStatement();
sql="update user set password='peisheng' where username='ps'";
ret=stmt.executeUpdate(sql);
// out.println("Hello world!!");
sql="delete from user where username='errr'";
ret=stmt.executeUpdate(sql);
sql="select * from user";
rs=stmt.executeQuery(sql);
while(rs.next())
{
String name=(String)rs.getString("username");
String pass=(String)rs.getString("password");
out.println("<tr>");
out.println("<td>"+name+"</td>");
out.println("<td>"+pass+"</td>");
out.println("</tr>");
}
out.println("Hello world");
rs.close();
stmt.close();
conn.close();
}catch(ClassNotFoundException e)
{
e.printStackTrace();
out.println("<h1>无法找到驱动!!</h1>");
}
catch(SQLException ex)
{
ex.printStackTrace();
out.println("数据库操作失败!");
}
%>
</table></font>
</body>
</html>