• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database Connection

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you loaded the Driver by
Class.forNAme(String DriverName).newInstance(); before DriverManager.getConnection ?
and what type of driver you using?
 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
BWA HA HA HA HA HA HA! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic