Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2008, 11:08 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Trace says that its unable to find MySql jdbc driver class.

Try adding the mysql jdbc driver jar file to project build path!


- Rakesh
 
Old September 30th, 2008, 02:17 PM
ruzdi
Guest
 
Posts: n/a
Default

can u plese tell me how can i add this . i want to know the procedure


 
Old September 30th, 2008, 02:18 PM
ruzdi
Guest
 
Posts: n/a
Default

can u plese tell me how can i add mysql jdbc driver jar file to project build path . i want to know the procedure
-Ruzdi


 
Old November 18th, 2008, 05:58 AM
Authorized User
 
Join Date: Jul 2007
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
Default

good working code, thanks...

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
http://coco4info.com/comment.aspx
http://commentdirectory.com/resources.aspx
 
Old December 3rd, 2008, 07:30 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

you can find information about setting classpath at the bellow given url

http://java.sun.com/j2se/1.4.2/docs/...classpath.html


- Rakesh
 
Old September 2nd, 2009, 09:56 AM
Registered User
 
Join Date: Sep 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ruzdi View Post
Dear Old Pedant ,
1> I am using netbean ide

2> One more thing after adding printStackTrace(); i found the following log

Exception: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
        at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at MissingRuzdi.MissingDbConnection.SqlConnection(Mis singDbConnection.java:28)
        at MissingRuzdi.MissingDbConnection.main(MissingDbCon nection.java:55)
BUILD SUCCESSFUL (total time: 0 seconds)
All you need is loading the driver class before calling DriverManger.getConnection.

put this
Class.forName("com.mysql.jdbc.Driver") and as long as you have mysql java connector jar file in your classpath, the driver should be able to connect.
Get the jar file from
http://dev.mysql.com/downloads/connector/j/5.1.html

It can't be any simpler.


They even have a quick start guide in the connector download that you can just copy paste.
 
Old October 27th, 2009, 03:10 AM
Registered User
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javanator

Hi ...... I had also faced the


Exception: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver


While connecting Java application to the mysql.
On both platform windows and linux

I m done with its solution and writing the steps i followed ... Hope it will help

1 . The java code for connectivity



import java.sql.*;

public class Jdbc11 {
public static void main(String args[]){

try {
Statement stmt;
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url,"root", "");
stmt = con.createStatement();
stmt.executeUpdate("CREATE DATABASE payroll1");
stmt.executeUpdate(
"GRANT SELECT,INSERT,UPDATE,DELETE," +
"CREATE,DROP " +
"ON JunkDB.* TO 'root'@'localhost' " +
"IDENTIFIED BY '';");
con.close();
}catch( Exception e ) {
e.printStackTrace();
}//end catch
}//end main
}//end class Jdbc11



This code on execution will create a database named payroll1......

2.
Mysql is installed by default on port 3306
if you will simply install the mysql and run the above code
you will get the

Exception: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

3
Here is the solution for this for windows


Simply put a file Named
" mysql-connector-java-3.0.17-ga-bin.jar "
(You can get this file easily downloadable on Internet , Search by
its name)
on the following location ... i m giving the location where i put it

" C:\Program Files\Java\jdk1.6.0_14\jre\lib\ext "



Simply paste the " mysql-connector-java-3.0.17-ga-bin.jar "
file over the above location relative to your machine....

After this execute the code it will gonna work fine....
Our editors will seek connector on the above location
but for deployed application read below....

Secondly when you will deploy your connectivity code into an
application , then u will have to save the connector
" mysql-connector-java-3.0.17-ga-bin.jar "
on the following location
i m giving the location where i put it
" C:\Program Files\Java\jre6\lib\ext "
deployed application will seek connector on this location...

it will gonna work fine after this....create stattement object and
execute as much query as you want
4
Here is the solution for Linux

simply put the connector
" mysql-connector-java-3.0.17-ga-bin.jar "

on the following location...i m giving the location where i put it
"/usr/lib/jvm/default-java/jre/lib/ext "

i need to restart the system to verify whether i wrote the right location for linux...Because i m working on windows right now...so forgive and work yourself to find the exact location ,,but trust me i think i wrote the right location....try your self....



Do Reply

Last edited by rohitgeminiSADTM; October 27th, 2009 at 04:58 AM..
 
Old November 24th, 2009, 06:54 AM
Registered User
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default database connection with mysql

import java.sql.Connection;
import java.sql.DriverManager;


/**
*
* @author mairaj
*/
public class DB {
static Connection con =null;
public static Connection getCon(){
try{
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql:\\localho st:3306\test","root","root") ;
}
catch(Exception e){}
return con;
}

}
 
Old December 11th, 2010, 03:22 AM
Registered User
 
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ruzdi View Post
Hi Friends,
Can you please tell me the procedure of java and mysql connection using jdbc driver . Please help me.
You can read all about JDBD on this site.

http://sunjava-expert.blogspot.com/2...onnection.html

http://sunjava-expert.blogspot.com/search/label/JDBC
 
Old May 12th, 2012, 06:16 AM
Registered User
 
Join Date: Aug 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default mysql connection using java

Quote:
Originally Posted by ruzdi View Post
Hi Friends,
Can you please tell me the procedure of java and mysql connection using jdbc driver . Please help me.
Hi,ruzdi

this code will definately help you,

import="java.sql.*"


try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase?","root","root");
Statement st=conn.createStatement();



// your code goes here...

//close try block

conn.close();
}catch(Exception e){
System.out.println("error"+e);
}


//3306 is default portnumber of mysql

//mydatabase is databasename in mysql

//root is username

//root is password

It will work 100%

Try it..


All the best..





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# and mySQL Connection naifwonder C# 5 March 8th, 2008 01:52 PM
making an mysql connection Zoe-Alyssa Dreamweaver (all versions) 0 May 19th, 2006 02:16 PM
java/jsp and MySQL harshika Java Databases 2 August 2nd, 2005 02:07 AM
use ODBCDataAdapter Connection MySQL kofallen Classic ASP Databases 2 April 19th, 2005 03:02 PM
Mysql connection catab C# 4 December 7th, 2003 11:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.