Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JDBC to connect to MYSQL

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have successfully installed My SQL on my machine and have been given the following code to load the driver's which works to a certain extent:

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

public class LoadDriver
{
public static void main (String [] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Driver Loaded");
}
catch (Exception ex)
{
System.out.println("Failure");
}
try
{
Connection conn = DriverManager.getConnection
("jdbc:mysql://localhost/menagerie");
System.out.println("Connection = " + conn);
}

catch (SQLException ex)
{
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}

The java is compiled in a file on my desktop but when I run it, whilst running MySQL, its output is:
Driver Loaded
SQLException: Access denied for user ''@'localhost(using password:no)
SQLState:28000
VendorError: 1045.

I can get into SQL ok by using a password but JDBC is another matter.I realise this is more of a MYsql issue but the MySQL forum is not at all helpful on tis issue despite it being an apparently frequent problem.

Any hints appreciated, apologies if it's something obvious I've missed!
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check your DBMS documentation, some have default user-names and/or passwords, if not, call DriverManager.getConnection(URL, "", "");
 
And Green
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats fantastic mate, worked first time. I'd spent five hours on the MySQL forum last night trying to figure this one out. Priceless.
 
reply
    Bookmark Topic Watch Topic
  • New Topic