aspose file tools*
The moose likes JDBC and the fly likes Using jdbc from jsp with MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using jdbc from jsp with MySQL" Watch "Using jdbc from jsp with MySQL" New topic
Author

Using jdbc from jsp with MySQL

Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
Hi, I am attempting to connect to a MySQL database I just created and I believe I am missing some java piece. I have installed the NetBeans IDE 4.1 and MySQL 5.0. I have created users for the database, created tables, and can access the tables from query tools. Now I am hoping to query the database from a jsp page.



However, when I try to run this jsp page it yields the following error:


Any ideas?


SCJP
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I think you have forgot to place jar file of mysql driver in WEB-INF/lib jar file


Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
That is some great advice!

Where do I obtain the JAR file? I have been looking all over the web for hours on getting this thing going and I really appreciate any pointers you might have.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I haven't worked on mysql so I am not quite sure about jar file, But look for mysql-connector-java-3.1.12-bin.jar

shailesh
Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
Thanks Shailesh,

Okay, I found a link where I can get the jdbc driver for the mysql server. It is located here for anyone following this thread:

http://www.mysql.com/products/connector/j/

It unzips into a ton of help files, and then also the file

mysql-connector-java-3.1.13-bar.jar

I tried copying this into my Web-INF folder so I placed

mysql-connector-java-3.1.13-bar.jar into the folder
c:\Dev\Web\Netbeans_projects\Web\WEB-INF

I am still getting this error when running the web page




Do I need to register the jar file somehow? Change the classpath perhaps? Any ideas?
[ September 26, 2006: Message edited by: Tom Joiner ]
Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
Add the full path to the classpath variable of the server startup script.
George Stoianov
Ranch Hand

Joined: Jan 15, 2006
Posts: 94
When you run a jsp in a servlet container the servlet container compiles the jsp into a servlet and runs it. That is why you should put it where the servlet container can find it so that it can compile your code.

If you are using Tomcat you can place it in <JAKARTA_HOME>/common/lib so that it is available for all applications you will write using mysql or in the lib folder of the respective webapp. If you are not using Tomcat the solution is pretty much the same find the manual and you will figure it out.

Good luck!
George
Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
Thanks for the idea. I am not sure where the startup script is, I assume it is accessible from the IDE. So I have now tried the following:

going to the web project, right click for properties.
Choose libraries
Choose the tab that says "compile tests"

Then, I click "add jar/folder" and browse to the jar file

Then choose the tab that says "run tests"

Then I click "add jar/folder" and browse to the jar file

Now I would assume this would be added to my class path for startup

but it doesnt work

ideas?
Deyu Wang
Greenhorn

Joined: Sep 26, 2006
Posts: 6
I think you should do this :
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}

replace to:

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


SCJP
Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
Thanks for all the ideas.

After much experimentation, it turned out I was putting the jar file into
WEB-INF/Lib/Jar

and it needed to go into
WEB-INF/Lib

So now I can query my database! It is time to start constructing accounts, and putting together some actual content, servlets, and so forth.

Thank you all for your assistance in this. It is very frustrating to come against a large toolkit which has many layers of possibilities of functioning. Your answers provided me with the needed context with which to effectively search on google.
 
jQuery in Action, 2nd edition
 
subject: Using jdbc from jsp with MySQL
 
Similar Threads
Hi im getting IllegalState exception when im trying to use sitemesh , any help pleas
JDBC in JSP not working
problem with the name attribute of form tag
JSP: Unable to connect to mysql in local drive [Solved]
MySQL