I am asking for user input in index.jsp, and I am taking this input in another search.jsp, where I am looking for a database with this request. However, it does not connect to the database. Can someone please help me.
Here is my code in index.jsp that asks for user input
<form method="searchh" action="search.jsp">
<table>
<tr>
<td><b class="accent">Enter College Name: </b> </td>
<td><input type="text" name="college" STYLE="color: #f4d442; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;" size="10" maxlength="30"></td>
<td> <input type="submit" value="Search Your College" <a href="#submit" class="btn btn-default btn-lg btn-satact" role="button"></a>></td>
</tr>
</table>
</form>
And here is my code in search.jsp . The database name / url / id / password is entered correctly. I used the same code for another search file. It works fine in this file. However, it does not connect to the database in this .jsp file. Here is my code for search.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<!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>Insert title here</title>
</head>
<body>
<%
try {
//Create a connection string
String url = "my_data_base_link";
//Load JDBC driver - the interface standardizing the connection procedure. Look at WEB-INF\lib for a mysql connector jar file, otherwise it fails.
Class.forName("com.mysql.jdbc.Driver");
//Create a connection to your DB
Connection con = DriverManager.getConnection(url, "user", "pass");
//Create a SQL statement
Statement stmt = con.createStatement();
String college = request.getParameter("college");
String str = "SELECT College, TUITIONFEE_IN, State FROM my_project1.all WHERE College LIKE " + "'" + college + "%'";
ResultSet result = stmt.executeQuery(str);
con.close();
} catch (Exception ex) {
out.print("insert failed");
}
It prints an insert with an error in the try and catch trap. Any help is appreciated.