aspose file tools*
The moose likes JDBC and the fly likes Database Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Connection" Watch "Database Connection" New topic
Author

Database Connection

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
hi all,
I am trying to talk to mysql(4.0.15-nt) database on my local machine(OS Win XP Home) from a java program.
In oracle there is something like this right ?
DriverManager.registerDriver(new OracleDriver())
I am sure there is one in MySql too,but I dont know what it is,let me know.....
So Far this is what I have done to establish the connection.
Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/<table-name>")
DatabaseConnection.getHandle(dbid)
But the compiler is giving the following error.Kindly let me know what is it that has to be done.
/*java.sql.SQLException: No suitable driver */
There is a list of errors/exceptions following that may be one leads to another,so thats the first line of the error.
Any help would be appreciated.
thanks
nash
BTW: I am set the classpath to the mysql-Connector.jar
Jan Figo
Greenhorn

Joined: Nov 26, 2003
Posts: 9
Have you loaded the Driver by
Class.forNAme(String DriverName).newInstance(); before DriverManager.getConnection ?
and what type of driver you using?


Take life as it comes!!!<br />~jan
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Thanks for the reply.This is what I have done.
The classpath is shown below
set classpath=.;D:\j2sdk1.4.2_01\jre\lib\ext\mysql-connector-java-3.0.9-stable-bin.jar
Let me know whether this is the right one.
I dont know what Driver you are talking about.
Let me know,help would be appreciated
nash
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hi,
Disregard the previous mail,The driver I am using is
"org.gjt.mm.mysql.Driver",is this ok.
I have registered the driver by using the clue you gave me,
I am now trying to establish a connection.....
This is how I am doing it,
String url = "jdbc:mysql://localhost:3306";
then..
this is what I do,
Connection con = DriverManager.getConnection(url);
The error it gives is....
/*
java.sql.SQLException: Malformed URL 'jdbc:mysql://localhost:3306'.
at com.mysql.jdbc.Connection.<init>(Connection.java:537)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java :361)
*/
Kindly help me out.
Thanking you
nash
Jan Figo
Greenhorn

Joined: Nov 26, 2003
Posts: 9
OK,
Heres what u do!!

String url = "jdbc:mysql://localhost:3306/<databasename>";
or
String url = "jdbc:mysql://localhost/<databasename>";
Connection con = DriverManager.getConnection(url,username,password);
keep empty strings if u dont have a username and password.
Try it out n see if itt works for u
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
hi,
Thanks for the reply.It does work.But I have a question.I want to give a userid and password,How do I go about doing that?.
Let me know

nash
Jan Figo
Greenhorn

Joined: Nov 26, 2003
Posts: 9
Hi,
good to know the method working for u!!
if u have to set the username and password i guess u have to set when u create the database.
i think this command is "grant privileges" or "create user"
if any one else knows how to set username n password , plz let me know too
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Connection