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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JSP and MySQL" Watch "JSP and MySQL" New topic
Author

JSP and MySQL

Sen Aff
Ranch Hand

Joined: Mar 08, 2007
Posts: 63
Hello,

I am trying to write a JSP program that will connect to my database.
I use NetBeans and I have created a database in MySQL called School.

I looked at some sample codes online and did not understand the following;


1. Class.forName("org.gjt.mm.mysql.Driver");
What does the "org.gjt.mm.mysql.Driver" stand for? Other programs I looked at just have "Driver".

2.dbconn = DriverManager.getConnection("jdbc:mysql://localhost/mydatabase";
Here, i guess the program is trying to connect to the database but my question is how do you configure Tomcat to work with MySQL?

Thanks you very much for your concern.

Sen Aff.
Hari Kumar Kempula
Greenhorn

Joined: Apr 18, 2007
Posts: 1
Hi
here is your answer go through this link to get your query clarified.





Using the MySQL
JDBC Driver
Sen Aff
Ranch Hand

Joined: Mar 08, 2007
Posts: 63
Hello,

I followed the instruction but I had a runtime exception.

this is what is in my code:
....
String URL = "jdbc:mysql:localhost:8084/Practice/School?user=root&password=password";
.....
try {
con = DriverManager.getConnection(URL);
......

and this is the error i hadrg.apache.jasper.JasperException: Exception in JSP: /ShowStu.jsp:51

48: Connection con = null;
49:
50: try {
51: con = DriverManager.getConnection(URL);


root cause
javax.servlet.ServletException: No suitable driver found for jdbc:mysql:localhost:8084/Practice/School?user=root&password=password

Thanks for your help and time.

Sen Aff.
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
According to http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html:


...the jar file for your JDBC driver should be installed in $CATALINA_HOME/common/lib


This requirement will be the same for other versions of Tomcat.
Sen Aff
Ranch Hand

Joined: Mar 08, 2007
Posts: 63
Hi Kevin,

I tried to open the link you gave but it was invalid
http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html:

I am using the Tomcat that comes bundled with NetBeans and I loaded the driver in the Libraries folder under my project folder.

Thanks a lot for your help.

Sen Aff.
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html
Sen Aff
Ranch Hand

Joined: Mar 08, 2007
Posts: 63
Hi,

I have followed the instructions you gave me but i
still get the same error.

org.apache.jasper.JasperException: An exception occurred processing JSP page /ShowStu.jsp at line 52

49:
50:
51: try {
52: con = DriverManager.getConnection(URL, user, pd);
53:


Can anyone please help me out? Thanks.

Sen Aff.
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
Originally posted by Sen Aff:

....
String URL = "jdbc:mysql:localhost:8084/Practice/School?user=root&password=password";
.....
try {
con = DriverManager.getConnection(URL);
......

and this is the error i hadrg.apache.jasper.JasperException: Exception in JSP: /ShowStu.jsp:51

48: Connection con = null;
49:
50: try {
51: con = DriverManager.getConnection(URL);


root cause
javax.servlet.ServletException: No suitable driver found for jdbc:mysql:localhost:8084/Practice/School?user=root&password=password


The URL you are using is incorrect. Check the MySQL JDBC driver docs for the correct format for the url.

[ June 01, 2007: Message edited by: Kevin Mukhar ]
[ June 01, 2007: Message edited by: Kevin Mukhar ]
Sen Aff
Ranch Hand

Joined: Mar 08, 2007
Posts: 63
Hello,

Thanks a lot for the help. I find out that the URL was not
properly written and I had to download a new driver....
mysql-connector-java-3.1.11-bin.

It works now.

Thanks once again.

sen Aff.
 
jQuery in Action, 2nd edition
 
subject: JSP and MySQL