Connecting To Mysql On Tch Server Using Jsp On Localhost

liunx

Guest
Hi all,<br /><br />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).<br /><br />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.<br /><br />I start here (database1.jsp):<br /><br /><html><br /><head><br /><title><br />Database Testing<br /></title><br /></head><br /><br /><body><br /><h1><br />Database Access Test<br /></h1><br /><br /><form action="database2.jsp" method=get><br />Enter username:<br /><input type=test name=username><br /><input type=submit value="Submit"><br /></form><br /><br /></body><br /></html><br /><br />--------------------------------------------<br /><br />Which goes here (database2.jsp):<br /><br /><html><br /><head><br /><%@ page<br />import = "java.io.*"<br />import = "java.lang.*"<br />import = "java.sql.*"<br />%><br /><br /><title><br />Database Access Test 2<br /></title><br /><br /><body><br /><%<br />int errorpoint = 0;<br />String driver = "org.gjt.mm.mysql.Driver";<br />String url = "jdbc:mysql://www.capellan.us:3306/<cpanel_username>_test";<br />String user = "<cpanel_username>_tester";<br />String pass = "testpass";<br />String username;<br />Connection dbconn;<br />ResultSet results;<br />PreparedStatement sql;<br /><br />try<br />{<br />Class.forName(driver).newInstance();<br />try<br />{<br />String userpass;<br />boolean doneheading = false;<br />errorpoint = 1;<br />dbconn = DriverManager.getConnection(url, user, pass);<br />errorpoint = 2;<br />username = request.getParameter("username");<br />errorpoint = 3;<br />sql = dbconn.prepareStatement("SELECT * FROM user WHERE username = '" + username + "'");<br />errorpoint = 4;<br />results = sql.executeQuery();<br />errorpoint = 5;<br />while(results.next())<br />{<br />if(! doneheading)<br />{<br />out.println("<table border=2>");<br />doneheading = true;<br />}<br />userpass = results.getString("userpass");<br />}<br />if (doneheading)<br />{<br />out.println("</table>");<br />}<br />else<br />{<br />out.println("No matches for " + username);<br />}<br />}<br />catch (SQLException e)<br />{<br />out.println(errorpoint);<br />out.println("SQL Error<br>"+e.getErrorCode());<br />}<br />}<br />catch (ClassNotFoundException err)<br />{<br />out.println("Class loading error");<br />}<br />%><br /><br /></body><br /></html><br /><br /><br />Any ideas?<!--content-->
Welcome to the forum, capellan. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums capellan <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />Have you given your laptop IP host access in cPanel?<!--content-->
Yeah, I followed another post by Andy from some time back about using % as a wildcard in the "allowed hosts" section.<!--content-->
Well its either because I updated my driver or I set the CLASSPATH environmental variable correctly, but I am able to connect now. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Thanks for the help. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tchrocks!.gif" style="vertical-align:middle" emoid=":tchrocks!:" border="0" alt="tchrocks!.gif" /><!--content-->
Thank you for the update.<!--content-->
 
Back
Top