Hi all,
I was hoping I might be able to find someone here with some experience using JSP that can help me connect a JSP page running on Tomcat from my laptop to a MySQL database on a TCH server. I'm new to using JSP; it's something I'm required to learn for a project in a database course (I was not lucky enough to get assigned PHP or ASP which seem like they would be easier).
I have a variable (errorpoint) that tells me where the code is stopping at. It stops right after errorpoint = 1 (see code for database2.jsp below). The SQLException getErrorCode() error integer that returns was 1045, but now it just shows 0.
I start here (database1.jsp):
<html>
<head>
<title>
Database Testing
</title>
</head>
<body>
<h1>
Database Access Test
</h1>
<form action="database2.jsp" method=get>
Enter username:
<input type=test name=username>
<input type=submit value="Submit">
</form>
</body>
</html>
--------------------------------------------
Which goes here (database2.jsp):
<html>
<head>
<%@ page
import = "java.io.*"
import = "java.lang.*"
import = "java.sql.*"
%>
<title>
Database Access Test 2
</title>
<body>
<%
int errorpoint = 0;
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://www.capellan.us:3306/<cpanel_username>_test";
String user = "<cpanel_username>_tester";
String pass = "testpass";
String username;
Connection dbconn;
ResultSet results;
PreparedStatement sql;
try
{
Class.forName(driver).newInstance();
try
{
String userpass;
boolean doneheading = false;
errorpoint = 1;
dbconn = DriverManager.getConnection(url, user, pass);
errorpoint = 2;
username = request.getParameter("username");
errorpoint = 3;
sql = dbconn.prepareStatement("SELECT * FROM user WHERE username = '" + username + "'");
errorpoint = 4;
results = sql.executeQuery();
errorpoint = 5;
while(results.next())
{
if(! doneheading)
{
out.println("<table border=2>");
doneheading = true;
}
userpass = results.getString("userpass");
}
if (doneheading)
{
out.println("</table>");
}
else
{
out.println("No matches for " + username);
}
}
catch (SQLException e)
{
out.println(errorpoint);
out.println("SQL Error<br>"+e.getErrorCode());
}
}
catch (ClassNotFoundException err)
{
out.println("Class loading error");
}
%>
</body>
</html>
Any ideas?