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

Re: facing problem in database connectivity in java to mysql

 
0
  #11
Dec 9th, 2007
thanx to all of u friends. mt problem was solved by putting connector :mysql-connector-java-3.0.16-ga-bin.jar in jdk ----jre folder in lib----ext and also copy it in tomcat---lib.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: Ahmed Zizo is an unknown quantity at this point 
Solved Threads: 1
Ahmed Zizo Ahmed Zizo is offline Offline
Newbie Poster

Re: facing problem in database connectivity in java to mysql

 
0
  #12
Dec 10th, 2007
that is great , but u can register ur driver by putting this line
DriverManager.registerDriver((driver)d.newInstance());
before u creat the connection
it is good programming practice
and
also u would update JDK to solve this problem in the code
Zizo
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: facing problem in database connectivity in java to mysql

 
0
  #13
Dec 10th, 2007
Originally Posted by muskan View Post
thanx to all of u friends. mt problem was solved by putting connector :mysql-connector-java-3.0.16-ga-bin.jar in jdk ----jre folder in lib----ext
Which is exactly the wrong place for it. Never place third party libraries here.
and also copy it in tomcat---lib.
tomcat/common/lib is the proper place (or is it tomcat/lib/common, anyways, only one of those places exist)
Last edited by masijade; Dec 10th, 2007 at 2:55 am.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: vaibhav.galne is an unknown quantity at this point 
Solved Threads: 0
vaibhav.galne vaibhav.galne is offline Offline
Newbie Poster

Re: facing problem in database connectivity in java to mysql

 
0
  #14
Mar 24th, 2009
You are facing problem while connecting to mysql database ......
i am forwarding you sample code hope this will ressolve u r problem.

code:
import java.sql.*;

public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}



follow simple code and make sure mysql connector jar should be in u r classpath.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: facing problem in database connectivity in java to mysql

 
0
  #15
Mar 24th, 2009
Originally Posted by vaibhav.galne View Post
You are facing problem while connecting to mysql database ......
i am forwarding you sample code hope this will ressolve u r problem.

code:
import java.sql.*;

public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
completely unnecessary, nothing to do with the problem, and poorly written. Close the resources in a finally block.



follow simple code and make sure mysql connector jar should be in u r classpath.
This was the problem. Of course, you do realise that this thread is over a year old, right?
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
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