•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 402,543 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,372 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 444 | Replies: 1
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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........
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
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?
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 '%
"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?
Last edited by masijade : Nov 7th, 2007 at 1:36 am. Reason: typo
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Internet speeds way down along with connectivity (Viruses, Spyware and other Nasties)
- database connectivity in c++ (C++)
- System 32 Coming Up at Startup (Viruses, Spyware and other Nasties)
- hijackthis log...I need help please (Viruses, Spyware and other Nasties)
- LSP Provide '' Missing - Hijack Log enclosed (Viruses, Spyware and other Nasties)
- Can't remove "about:blank" homepage. Please help. (Viruses, Spyware and other Nasties)
Other Threads in the JSP Forum
- Previous Thread: how to update database using mysql and jsp
- Next Thread: jsp projects



Linear Mode