Hi,
I am new to mysql connectivity using jsp. but i have tried it with MS Access nd it worked out for me.

I have installed jdk1.4, Tomcat5.0, mysql 4.1 and mysql_connector_odbc_3.51.21_win32.msi. For the following code i am getting error code 500..

I have set the Env paths as

path %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\Common Files\Adaptec Shared\System;C:\Program Files\Java\jdk1.5\bin;C:\Program Files\Java\jdk1.5\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\bin;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\MySQL\MySQL Server 4.1\bin;C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Mysql\WEB-INF\lib\mysql-connector-java-3.0.15-ga-bin.jar;

Where Mysqls folder containing files in webapps,

Can u Plz tel me how to solve it. As per i found its error in Driver.Manager statement.

<html>
<head><br><br>
<center>Data retreived from data base(If Retreives)</center><br><hr><br><br>
</head>
<body>


<%@ page language="java" import="java.sql.*, java.io.*" %>
<%
String userName = null;
String Password = null;


userName = request.getParameter("user");
Password = request.getParameter("pswd");



Connection con = null;



try {



Class.forName("org.gjt.mm.mysql.Driver");


con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Rajesh","root","mysql");


Statement statement = con.createStatement();


ResultSet rs = statement.executeQuery("SELECT * FROM prim WHERE name = '"+userName+"'");


while ( rs.next() ) {
%>
<p><h1>Welcome  <%= userName %>!</h1></p>
<p>Your no is: <%= rs.getString("no") %></p>
<p>Your setno no.is: <%= rs.getString("setno") %></p>
<%
}


rs.close();
//System.in.read();
}
catch (IOException ioe) {
System.err.println(ioe.getMessage());
ioe.printStackTrace();


}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
sqle.printStackTrace();
}
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe.getMessage());
cnfe.printStackTrace();
}
catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
finally {
try {
if ( con != null ) {
con.close();
}
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
}
%>



</body>
</html>

Plz give solution for my problem........

Every time an error occurs in a JSP you will get a 500 http code at the browser. That does not tell us anything. It would really help to include that actual error.

But in general, move all this scriptlet stuff out of the JSP and into a Bean.

Tomcat has a Connection Pooling resource, use that, don't make the connection in the JSP, that causes a new connection to be made with every page load. Very bad for performance (and no way of controlling the amount connections that may be opened).

Use a PreparedStatement and its setString method rather than cobbling together a statement like that. What would happen if the user entered something like this for a username

'; delete * from prim where name like '%

Perfectly valid SQL and it would delete everything from your prim table (and that is a very mild example of what can happen). A PreparedStatement would prevent that sort of thing.

"org.gjt.mm.mysql.Driver" is an ancient Driver, only still included in the MySQL Driver distribution for backwards compatability. Use "com.mysql.jdbc.Driver" as the MySQL documentation recommends.

Nowhere in that code are you closing the statement object. Could be very bad even when you do close the connection. Close that in the finally block as well.

Close the ResultSet in the finally block, also.

I believe that's enough for now.

Let me guess, you got the example you used for creating this from roseindia, right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.