Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using jdbc from jsp with MySQL

 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have forgot to place jar file of mysql driver in WEB-INF/lib jar file


Shailesh
 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the full path to the classpath variable of the server startup script.
 
George Stoianov
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should do this :
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}

replace to:

{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic