473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

JSP/MySql and JDBC/MySql

ak1dnar
1,584 Recognized Expert Top Contributor
I have downloaded and copied the this Connector/j to lib directory of my java installation dir.

and this Jsp page is working with that.

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*" %>
  2.  
  3. <%
  4.     String driver = "org.gjt.mm.mysql.Driver";
  5.     Class.forName(driver).newInstance();
  6.  
  7.  
  8.     Connection con=null;
  9.     ResultSet rst=null;
  10.     Statement stmt=null;
  11.  
  12.  
  13.     try
  14.     {
  15.         String url="jdbc:mysql://localhost/books?user=root&password=dba";
  16.         con=DriverManager.getConnection(url);
  17.         stmt=con.createStatement();
  18.         out.println("Connected");
  19.     }
  20.     catch(Exception e)
  21.     {
  22.         out.println(e.getMessage());
  23.     }
  24. %>
But I couldn't get connect with this java file.

Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3. public class LoadDriver
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         try
  8.         {
  9.         Connection con=null;
  10.         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  11.         String url="jdbc:mysql://localhost/books?user=root&password=dba";
  12.         con=DriverManager.getConnection(url);
  13.         System.out.println("Connected...");
  14.         }
  15.         catch (Exception ex)
  16.         {
  17.            System.out.println(ex.getMessage());
  18.         }
  19. }
  20. }
The exception is the name of the driver. how to solve this problem.
Mar 29 '07 #1
4 2711
menmysql
53 New Member
hey i got connected with your code only why ur not
can you send what error ur getting.iam waiting for ur reply

I have downloaded and copied the this Connector/j to lib directory of my java installation dir.

and this Jsp page is working with that.

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*" %>
  2.  
  3. <%
  4.     String driver = "org.gjt.mm.mysql.Driver";
  5.     Class.forName(driver).newInstance();
  6.  
  7.  
  8.     Connection con=null;
  9.     ResultSet rst=null;
  10.     Statement stmt=null;
  11.  
  12.  
  13.     try
  14.     {
  15.         String url="jdbc:mysql://localhost/books?user=root&password=dba";
  16.         con=DriverManager.getConnection(url);
  17.         stmt=con.createStatement();
  18.         out.println("Connected");
  19.     }
  20.     catch(Exception e)
  21.     {
  22.         out.println(e.getMessage());
  23.     }
  24. %>
But I couldn't get connect with this java file.

Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3. public class LoadDriver
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         try
  8.         {
  9.         Connection con=null;
  10.         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  11.         String url="jdbc:mysql://localhost/books?user=root&password=dba";
  12.         con=DriverManager.getConnection(url);
  13.         System.out.println("Connected...");
  14.         }
  15.         catch (Exception ex)
  16.         {
  17.            System.out.println(ex.getMessage());
  18.         }
  19. }
  20. }
The exception is the name of the driver. how to solve this problem.
Mar 29 '07 #2
menmysql
53 New Member
sorry i did not mentioned in my previous post i.e., i got only in jsp and not in java file. i am also intrested in this topic. if you got any replys plz keep here i will try to refer


thanku
Mar 29 '07 #3
ak1dnar
1,584 Recognized Expert Top Contributor
This is the installation Mannual for Connector/j, Only thing i did for now I just copied that jar file and put it to the lib directory in JAVA installation dir. and it works for my JSP apps. but the problem with Java. as the exception its returning this class names.

i used both com.mysql.jdbc.Driver and org.gjt.mm.mysql.Driver

Installing the Driver and Configuring the CLASSPATH
Once you have extracted the distribution archive, you can install the driver by placing mysql-connector-java-[version]-bin.jar in your classpath, either by adding the full path to it to your CLASSPATH environment variable, or by directly specifying it with the command line switch -cp when starting your JVM.

If you are going to use the driver with the JDBC DriverManager, you would use com.mysql.jdbc.Driver as the class that implements java.sql.Driver.
Mar 30 '07 #4
zubair Alam
1 New Member
Hello Sir,
i have recieve u r solution but i write same code but herewith classNotFound exception is arising
Apr 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
7
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
5
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
3
by: tulika dutta | last post by:
after 8 hrs my MySQL connection with JDBC gets time out. It gives the error java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying...
1
by: vincedav31 | last post by:
I have a connection to a server and my database. I use it like this in my code : Class.forName("com.mysql.jdbc.Driver"); String DBurl = "jdbc:mysql://138.63.222.7:3306/ns3"; m_connection =...
1
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter...
1
by: manjava | last post by:
Hello, i have a class java conncet to database mysql when i execute the classe alone so execute but when i want to execute this link on web...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.