HTTP状态500 - 服务器遇到内部错误(),导致无法完成此请求

时间:2014-11-25 20:06:34

标签: java sql jsp

嘿伙计们我得到这个错误,我现在有想法如何解决它。这是我的代码:

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<html>
<head>
    <title> Retrieve data from database</title>
</head>

<body>
    <h1>Database Search</h1>
    <Form method="post">
        Please enter the id of the House you want to find:
        <br>
        <input type="text" name="id">
        <br>
        <input type="submit" value="Submit">
    </Form>

    <h1>Fetching data from database</h1>

    <%

        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        String database_url = "jdbc:mysql://localhost:3306/jsp";
        String user = "root";
        String pass = "1234";

        Connection con = java.sql.DriverManager.getConnection(database_url, user, pass);

        Statement statement = con.createStatement();

        String id = request.getParameter("id");

        String query ="select * from houses where id = '" + id + "'";
        ResultSet resultset = statement.executeQuery(query);

        if(!resultset.next()){
            out.println("Sorry, could not find house");
        }
        else{
    %>

    <table border ="1">
        <tr>
            <th>Id</th>
            <th>Address1</th>
            <th>Address2</th>
            <th>Address3</th>
            <th>City</th>
            <th>State</th>
            <th>Postcode</th>
            <th>Bedrooms</th>
            <th>Status</th>
        </tr>
        <tr>
            <td> <%= resultset.getString(1) %> </td>
            <td> <%= resultset.getString(2) %> </td>
            <td> <%= resultset.getString(3) %> </td>
            <td> <%= resultset.getString(4) %> </td>
            <td> <%= resultset.getString(5) %> </td>
            <td> <%= resultset.getString(6) %> </td>
            <td> <%= resultset.getString(7) %> </td>
            <td> <%= resultset.getString(8) %> </td>
            <td> <%= resultset.getString(9) %> </td>
        </tr>
    </table>
    <br>
    <% 
        }
      %>  
    </body>
</html>

我得到了错误

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 27

    24:         
    25:         <%
    26:             
    27:             Class.forName("net.sourceforge.jtds.jdbc.Driver");
    28:             String database_url = "jdbc:mysql://localhost:3306/jsp";
    29:             String user = "root";
    30:             String pass = "1234";

有没有人有同样的问题可以帮助或知道如何解决它。 提前致谢

0 个答案:

没有答案