Hello everyone, I'm working on a project where I wish to find out who the instructor for a particular course is. The user is has to input the course name and course id for that course id then the script will search for the instructor. If the value returned is null (instructor not found), the user will be asked to refine his search. But if all goes well the user will be supplied with the information he needs.
But for some reason when I try the code I came up with, all I get is a blank screen.
This is what came up with so far:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%
Connection con = null; // object.
ResultSet rst = null; // object.
Statement stmt = null; // object.
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test2";
con = DriverManager.getConnection(url, "root", "123");
stmt = con.createStatement();
String id = request.getParameter("id");
String Course_name = request.getParameter("Course_name");
rst = stmt.executeQuery("select Instructor, id, Course_name from untitled where Course_name = " + Course_name + " and id = " + id);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Login Result:</h1>
<%
String Instructor = rst.getString("Instructor");
if (Instructor == null) {
%> Sorry, no match for that user in our database. Please try again.<%
} else if (Instructor != null){
%>
Hello %= Instructor%>, go to <a href="index.jsp">staff home</a> to begin.--> <%
}
rst.close();
stmt.close();
con.close();
} catch (ClassNotFoundException e) {
System.err.println("Could not load database Driver!");
} catch (SQLException e) {
System.err.println("Could not connect to to the database!");
}
%>
</body>
</html>
Any help is appreciated thanks in advance. :)