User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 456,610 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 3,487 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: 522 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 3
Reputation: Rajesh.D.N is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Rajesh.D.N Rajesh.D.N is offline Offline
Newbie Poster

Connectivity with mydwl using lsp

  #1  
Nov 7th, 2007
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........
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,519
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: Connectivity with mydwl using lsp

  #2  
Nov 7th, 2007
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?
Last edited by masijade : Nov 7th, 2007 at 2: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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 7:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC