File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP and MySQL

 
Sen Aff
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
here is your answer go through this link to get your query clarified.





Using the MySQL
JDBC Driver
 
Sen Aff
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
 
Sen Aff
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic