RSS Forums RSS
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 3123 | Replies: 19 | Thread Tools  Display Modes
Reply
Join Date: May 2007
Location: USA
Posts: 3,343
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 16
Solved Threads: 332
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Nearly a Senior Poster

Re: facing problem in database connectivity in jsp to mysql

  #11  
Aug 6th, 2007
Originally Posted by muskan View Post
yes i have copied the .jar files in WEB-INF/lib but still when i have compiled database connectivity program with mysql in java it gave the same error.

D:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - C:\final project\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;d:\program files\java\jdk1.5.0\lib\tools.jar;d:\program files\java\jdk1.5.0\jre\lib\rt.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

....

Why are you trying to run the ConnBean from the jdk bin folder if you wish to access this through Tomcat? If you want to run from the command line, you need to specify the classpath. Many posts have told you how to do that. If you have a JSP/servlet app running in Tomcat that needs that ConnBean, then placing the jar in WEB-INF/lib for that app is all that you need to do.
Reply With Quote  
Join Date: Aug 2007
Posts: 3
Reputation: Xolera is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Xolera Xolera is offline Offline
Newbie Poster

Re: facing problem in database connectivity in jsp to mysql

  #12  
Aug 6th, 2007
2masijade I beginner in java too. So sometimes copy jars to jre folder (when project not compiled and i am angry )

In attachment sent sample project for test MySQL connection. Maybe it helps TS to solve his problem.
Attached Files
File Type: zip jsp code.zip (534.4 KB, 1 views)
Reply With Quote  
Join Date: Feb 2006
Posts: 1,594
Reputation: masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all 
Rep Power: 11
Solved Threads: 147
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: facing problem in database connectivity in jsp to mysql

  #13  
Aug 7th, 2007
Originally Posted by Xolera View Post
2masijade I beginner in java too. So sometimes copy jars to jre folder (when project not compiled and i am angry )


And as a quick fix to get something compiled or run for the first time when you are frustated, and it is not meant as a solution, but rather just a quick stopgap, I don't object to it that much (although it still should not be done, it shouldn't get to that point, but sh1t happens sometimes). The real problem comes in (at least the point where I get upset about it) is when I see someone suggest that as the solution for a problem.
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  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,875
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 14
Solved Threads: 344
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: facing problem in database connectivity in jsp to mysql

  #14  
Aug 7th, 2007
It always start with quick fix, but in no time you find that quick fix project is project on which you work for weeks/months. You submit to your teacher/employer/customer to find "suddenly" it does not work for them.

So as masijade and others said it is always best to do it proper way.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Aug 2007
Posts: 3
Reputation: Xolera is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Xolera Xolera is offline Offline
Newbie Poster

Re: facing problem in database connectivity in jsp to mysql

  #15  
Aug 7th, 2007
I think for a beginner important to make the project efficient. And then to understand details. If the program does not work - that to test there is nothing. Though I too for the serious approach in development of commercial projects. But adjustment connector for a DB is not so critical in comparison with realization of architecture of the project. For example now I develop the project in team of developers. It stored on VSS and not depend on local settings developers computer. But its not thought over project architecture would be a big problem.
Reply With Quote  
Join Date: Jul 2007
Posts: 11
Reputation: muskan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
muskan muskan is offline Offline
Newbie Poster

Help Re: facing problem in database connectivity in jsp to mysql

  #16  
Aug 7th, 2007
Originally Posted by masijade View Post
Bad, bad, bad. Never copy anything to the lib/ext directory of the jre. Learn how to use and set classpaths properly. If he has the proper jarfile, and places it in the WEB-INF/lib directory of the web application he is trying to reach, the classes will be found. If they are not, he has done something wrong. Either copied it to the lib directory of the wrong application, not copied the right jarfile, or, maybe, somehow or another, changed the tomcat configuration so that it does not look there. Sorry to say it, but all of those things are "his problem", and copying anything to the lib/ext directory is not the answer, regardless of whether or not "it works".


1) i have copied mysql-connector-java-3.0.8-stable-bin this zipped file and also imn unzipped form in WEBINF/lib .which jar files u are talking about please mention complete name .and
2) tell me by doing this can i remove the error encountering in kawapro also as i have mentioned above .
Reply With Quote  
Join Date: Feb 2006
Posts: 1,594
Reputation: masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all 
Rep Power: 11
Solved Threads: 147
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: facing problem in database connectivity in jsp to mysql

  #17  
Aug 7th, 2007
If your application runs in tomcat, place any and all jarfiles that it needs into the WEB-INF/lib directory of the application. You should know what the jars are, since you are the one writing the application. If you can no longer remember the name of a specific jar, then download it again. If, after placing the jar(s) in WEB-INF/lib, you still get a ClassNotFoundException, then you have either copied it to the WEB-INF/lib directory of the wrong application, or you have done something to the Tomcat configuration which prevents it from loading libraries in that directory. What that might be, I cannot even begin to tell you. All of this, of course, assumes that you are accessing the application through Tomcat, and a browser, of course. If you are attempting to execute something from the command line, then you should use the -cp option to specify the classpath (specifying the full complete path to each individual jarfile needed) when you type java (if the class will even function from the command line, which Servlets and JSPs definately will not (and most, if not all Beans, also should not, except indirectly, i.e. accessed from a different class which is executed).
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  
Join Date: Jul 2007
Posts: 11
Reputation: muskan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
muskan muskan is offline Offline
Newbie Poster

Help Re: facing problem in database connectivity in jsp to mysql

  #18  
Aug 7th, 2007
oh my dear ! i am working with tomacat apache 5.0.28 but in order to work with beans there is also need to make a java file and place it in classes in tomcat directory .thats why i am running the program on jdk 1.5 +kawapro5 in order to connect the mysql database with jsp.
and the the jsp code is given below that i am using with this java file or class file


<%@page import="java.sql.*,java.util.*" %>
<jsp:useBean id="connBean" scope="page" class="ConnBean" />


<html>

<head>
<script>
function validate(f){
if(f.id.value.length == 0){
alert('User Id can no be empty.');
f.id.focus();
return false;
}
else if(f.pswd.value.length == 0){
alert('Password can no be empty.');
f.pswd.focus();
return false;
}
}
</script>
<title>Log In</title>
</head>

<body onLoad="document.login.id.focus()">
<center>
<%
String query="insert into dbname(id,password) values('2222','222')";
String url=request.getRemoteAddr();
try
{
int t=connBean.executeUp(query);
if(t>0)
out.print("query successfull");
else
out.print("query not successfull");
}
catch(Exception e)
{}

</body>

</html>

but how tomcat will run it properly untill its class file(.java file) works properly.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: facing problem in database connectivity in jsp to mysql

  #19  
Aug 8th, 2007
thats why i am running the program on jdk 1.5 +kawapro5 in order to connect the mysql database with jsp

God forbid you'r learn how to do things properly, right?

And your JSP is a disaster area. NEVER put Java code in a JSP. And ALWAYS close ALL database resources as soon as you're done with them.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,594
Reputation: masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all masijade is a name known to all 
Rep Power: 11
Solved Threads: 147
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: facing problem in database connectivity in jsp to mysql

  #20  
Aug 8th, 2007
Originally Posted by muskan View Post
oh my dear ! i am working with tomacat apache 5.0.28 but in order to work with beans there is also need to make a java file and place it in classes in tomcat directory .thats why i am running the program on jdk 1.5 +kawapro5 in order to connect the mysql database with jsp.


Servlets are also java files (and JSPs are too, indirectly, since they will be translated to one the first time accessed after being changed). There is no reason you cannot test the Bean inside of the application. I assume you know how it will be used, so simply perform those actions through the browser (and at first you can have the bean log all sorts of things as kind of a "ppor man's" debug). Either that or write a separate Class that does nothing but call all the methods of the Bean, and which contains a main method, and call that. Then, like I said, include all jars on the command line with the -cp option. It's not that hard.
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.



Similar Threads
Other Threads in the JSP Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:23 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC