连接到数据库失败,HTTP状态500

时间:2017-12-14 21:40:36

标签: java mysql jsp

当我尝试运行转发到连接到数据库的jsps的索引时,我在jsps上收到错误,数据库名称和一切都很好。

它给我的错误是 HTTP状态500 - 内部服务器错误 org.apache.jasper.JasperException:在第[25]行处理[/registration.jsp]时发生异常

22://它返回com.mysql.jdbc.Driver.class。 23: 24:
25:java.sql.Connection conn = DriverManager.getConnection(“jdbc:mysql:// localhost:3306 / employeeexample”,“root”,“1234”); 26:语句stmt = conn.createStatement(); 27:
28:// stmt.executeUpdate(“插入users2(user_id,密码,fname,lname,email)”+“values”+“(”+ user +“','”+ pwd +“','”+ fname +“' ' “+ L-NAME +”,' “+电子邮件+”')“);

它给我带来了LOGIN.JSP上的相同错误,但是它提供了直接与连接相对应的行号。

的login.jsp

SELECT TOP 1 ID, HoursWorked FROM HoursWorked ORDER BY HoursWorked DESC

REGISTRATION.JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration.jsp</title>
</head>
<body>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>

<%
String user = request.getParameter("user");
//session.putValue("userid",user);
String pwd = request.getParameter("pwd");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email= request.getParameter("email");

Class.forName("com.mysql.jdbc.Driver");
//it returns com.mysql.jdbc.Driver.class. 

 
   java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/employeeexample", "root","1234");
   Statement stmt = conn.createStatement();
  
  // stmt.executeUpdate("insert into users2(user_id,password,fname,lname,email)" +"values"+"("+user+"','"+pwd+ "','"+fname+"','"+lname+",'"+email+"')");
   stmt.executeUpdate
   ("insert into users2 values"+"('"+user+"','"+pwd+"','"+fname+"','"+lname+"','"+email+"')");
// stmt.executeUpdate("insert into users2(user_id,password) " + "values  ('"+user+"','"+pwd+"')");
  
   
  //stmt.executeUpdate("insert into users values("+pwd+ "','"+fname+"','"+lname+",'"+email+"')");
	ResultSet rs = stmt.executeQuery  ("SELECT * FROM users2 WHERE user_id ='"+ user + "'");
   
	
if(rs.next())
{
	
		out.println("welcome "+user);
	
}
   out.println(user+ " Registered");
  
%>

<a href = "Login.html"> Login</a>

<a href = "Registration.html"> Registration</a>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试捕获可能有助于了解问题所在:

<%
String user = request.getParameter("user");
//session.putValue("userid",user);
String pwd = request.getParameter("pwd");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email= request.getParameter("email");

    try {
       Class.forName("com.mysql.jdbc.Driver");

       java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/employeeexample", "root","1234");

       Statement stmt = conn.createStatement();

       // stmt.executeUpdate("insert into users2(user_id,password,fname,lname,email)" +"values"+"("+user+"','"+pwd+ "','"+fname+"','"+lname+",'"+email+"')");
       stmt.executeUpdate
       ("insert into users2 values"+"('"+user+"','"+pwd+"','"+fname+"','"+lname+"','"+email+"')");
       // stmt.executeUpdate("insert into users2(user_id,password) " + "values  ('"+user+"','"+pwd+"')");


       //stmt.executeUpdate("insert into users values("+pwd+ "','"+fname+"','"+lname+",'"+email+"')");
        ResultSet rs = stmt.executeQuery  ("SELECT * FROM users2 WHERE user_id ='"+ user + "'");


        if(rs.next())
        {

                out.println("welcome "+user);

        }
        out.println(user+ " Registered");
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }

%>