facing problem in database connectivity in java to mysql

Reply

Join Date: Jul 2007
Posts: 11
Reputation: muskan is an unknown quantity at this point 
Solved Threads: 0
muskan muskan is offline Offline
Newbie Poster

facing problem in database connectivity in java to mysql

 
-1
  #1
Jul 31st, 2007
please help me to resolve the databasbase connectivity problem in java for mysql .i am using jdk 1.5 ,if there is need to put a file then please mention where it should be copied ,and i am writing the code and error occuring that code.

code:


import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.*;
import java.io.*;

public class ConnBean
{
Connection conn;
Statement st ;
public ConnBean()
{
String sqlDriver= "com.mysql.jdbc.Driver";
String hostName = "localhost:3306/";
String dbName = "mydb";
String userID = "root";
String password = "webportal";

//databse URL
String dbURL = "jdbc:mysql://" + hostName + dbName;

try {
Class.forName(sqlDriver);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(dbURL, userID, password);
st = conn.createStatement();
System.out.println("db connected");
}
catch (SQLException e) {

System.out.println("Exception occured during get connection" + e);
}
}

public static void main(String asdas[]) throws SQLException
{

ConnBean conn=new ConnBean();


//ResultSet rs=conn.executeQ("select * from clients");
}
}


Error

D:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - C:\final project\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;d:\program files\java\jdk1.5.0\lib\tools.jar;d:\program files\java\jdk1.5.0\jre\lib\rt.jar
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.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at ConnBean.<init>(ConnBean.java:25)

at ConnBean.main(ConnBean.java:44)

Exception occured during get connectionjava.sql.SQLException: No suitable driver

Process Exit...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,363
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: facing problem in database connectivity in java to mysql

 
0
  #2
Jul 31st, 2007
You need to add the mysql driver jar to your classpath.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,126
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 472
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: facing problem in database connectivity in java to mysql

 
0
  #3
Jul 31st, 2007
That is exactly what he got as naswer in JSP section , plus closer description and he still doesn't do it
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 11
Reputation: muskan is an unknown quantity at this point 
Solved Threads: 0
muskan muskan is offline Offline
Newbie Poster

Re: facing problem in database connectivity in java to mysql

 
0
  #4
Aug 1st, 2007
please tell me how to put the mysql driver in the class path please mention the method kindly.thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1
Reputation: cnbaluramesh is an unknown quantity at this point 
Solved Threads: 0
cnbaluramesh cnbaluramesh is offline Offline
Newbie Poster

Re: facing problem in database connectivity in java to mysql

 
0
  #5
Aug 1st, 2007
you need to set the classpath.
copy the mysql-------.jar to in working directory and set the classpath.
set classpath=%classpath%;<your mysql-----.jar place path>;.;

try this and get back with result


Originally Posted by muskan View Post
please help me to resolve the databasbase connectivity problem in java for mysql .i am using jdk 1.5 ,if there is need to put a file then please mention where it should be copied ,and i am writing the code and error occuring that code.

code:


import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.*;
import java.io.*;

public class ConnBean
{
Connection conn;
Statement st ;
public ConnBean()
{
String sqlDriver= "com.mysql.jdbc.Driver";
String hostName = "localhost:3306/";
String dbName = "mydb";
String userID = "root";
String password = "webportal";

//databse URL
String dbURL = "jdbc:mysql://" + hostName + dbName;

try {
Class.forName(sqlDriver);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(dbURL, userID, password);
st = conn.createStatement();
System.out.println("db connected");
}
catch (SQLException e) {

System.out.println("Exception occured during get connection" + e);
}
}

public static void main(String asdas[]) throws SQLException
{

ConnBean conn=new ConnBean();


//ResultSet rs=conn.executeQ("select * from clients");
}
}


Error

D:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - C:\final project\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;d:\program files\java\jdk1.5.0\lib\tools.jar;d:\program files\java\jdk1.5.0\jre\lib\rt.jar
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.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at ConnBean.<init>(ConnBean.java:25)

at ConnBean.main(ConnBean.java:44)

Exception occured during get connectionjava.sql.SQLException: No suitable driver

Process Exit...
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 56
Reputation: staneja is an unknown quantity at this point 
Solved Threads: 1
staneja's Avatar
staneja staneja is offline Offline
Junior Poster in Training

Re: facing problem in database connectivity in java to mysql

 
0
  #6
Aug 1st, 2007
Hi..........in general what you can do is .....create one lib folder in your project and copy the driver file for connection in that and set calss path to your lib folder...........

set classpath ....u have to do this stem into system variables
My computer -: properties -: Advanced -:Environment variables
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,363
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 500
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: facing problem in database connectivity in java to mysql

 
0
  #7
Aug 1st, 2007
Classpath can also be set as a parameter in the javac command with the -cp (or -classpath) switch
  1. javac -cp .;%CLASSPATH%;c:/myProject/lib/aJarFile.jar myProgram.java
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: facing problem in database connectivity in java to mysql

 
0
  #8
Aug 1st, 2007
and RTFM. It's well explained in the documentation, if you took the trouble to read it which you didn't or you'd not have this "problem".
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,126
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 472
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: facing problem in database connectivity in java to mysql

 
0
  #9
Aug 1st, 2007
Unfortunately for us, our friend muskan made so many post about his problem on this forum that I lost track of which post is from which day or time. What I say for the sake of it is, I gave answer for this problem too, this was directly to Java Sun tutorial site explaining seting up PATH and CLASSPATH.
However muskan so far did not pay attention, if he/she not willing to the job who else should?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: facing problem in database connectivity in java to mysql

 
0
  #10
Aug 2nd, 2007
sounds like perfect manager material for a callcenter...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC