日期:2014-05-18  浏览次数:20753 次

jsp连接mysql数据库出错。。
org.apache.jasper.JasperException: Exception in JSP: /javascript/zhuce_insert.jsp:10

7: String driverName = "com.mysql.jdbc.Driver";
8: String url = "jdbc:mysql://localhost:3306/stu_inform";
9: Class.forName("com.mysql.jdbc.Driver");
10: Connection conn = DriverManager.getConnection(url,"root","");
11: Statement statement = conn.createStatement();
12: String sql = "insert into stu_record values(" + request.getParameter("stuname") + "," + Integer.parseInt(request.getParameter("stunum")) + "," + request.getParameter("stuem") + ")";
13: statement.executeUpdate("sql");


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

我的mysql已经启动,tomcat也已经启动,我不知道数据库的用户名和密码,不知道再哪看。反正进去就能用的,本来用户名和密码那我都填空的,但是不行,后来就加个root用户名上去了。
我将 mysql-connector-java-3.1.0-alpha-bin.jar
复制到了我的/tomcat/webapps/ROOT/WEB-INF/lib下了,不知道还需要什么配置没??请大家帮帮我,谢谢!!

------解决方案--------------------
statement.executeUpdate("sql"); //你要执行sql还是"sql"?
------解决方案--------------------
给你个工具类!
import java.sql.*;

public class Connector{

private String url="jdbc:mysql://localhost:3306/stu_inform";
private String driver="com.mysql.jdbc.Driver";
private String user="root";
private String pw="";

public static Connection getConnection()throws SQLException{

Class.forName(driver);
Connection conn=DriverManager.getConnection(url,user,pw);

return conn;


}

}


应该是你的密码不对,在安装mysql 时,应该是有密码的!

不行你就在CMD中,先把路径切换到你的数据库目录:
如c:/program files/Mysql/mysql server 5.2
然后敲入
mysql -uroot -p

会提示你输入密码,你可以在这试一下密码!

------解决方案--------------------
上面的路径应该是
C:/program files/mysql/mysql server 5.2/bin一定要到bin 下!