Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No suitable driver error.

 
LiL Kunji
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi. i realize this has been asked a millions times but here i go. this is part of the code:
public TableDisplay()
{

String url = "jdbc:mysql:Books";
String username = "foo";
String password = "foo";

try {
Class.forName( "org.gjt.mm.mysql.Driver" );
connection = DriverManager.getConnection(
url, username, password );
the driver org.gjt.etc... is downloaded and i put it in jre ext directory. which before i did this i kept getting class not found. so now that class is found i get the no suitable driver error. i set class path like this in case the ext dir did not work ATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\WINDOW;C:\WINDOWS\COMMAND;C:\JD
where JD is the the diretory that has the subdir org.... i seen an earlier case of this on the forum here where the problem was that his editor was overiding the classpath(uhh?) anyhow i use jcreator. my odbc source admin shows Books and mysql as its driver. i didn't quite understand the dns setup for the driver but i put Books in the windows dns field and click ok. iv'e been everwhere trying to figure this out but no go. any help would be great! thanks
 
LiL Kunji
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got the previous error solved but now i get this error:
Unable to connect
java.sql.SQLException: Invalid authorization specification: Access denied for us
er: 'root password@127.0.0.1' (Using password: NO)
at org.gjt.mm.mysql.MysqlIO.init(Unknown Source)
at org.gjt.mm.mysql.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at TableDisplay.<init>(TableDisplay.java:27)
at TableDisplay.main(TableDisplay.java:143)
Exception in thread "main" java.lang.NullPointerException
at TableDisplay.getTable(TableDisplay.java:54)
at TableDisplay.<init>(TableDisplay.java:40)
at TableDisplay.main(TableDisplay.java:143)
what i changed the getConnection parameters to : "jdbc:mysql://localhost:3306/Books ?user=foo password=foo" but now getting the upper error. any help would be great. thank you
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by LiL Kunji:
ok i got the previous error solved but now i get this error:
Unable to connect
java.sql.SQLException: Invalid authorization specification: Access denied for us
er: 'root password@127.0.0.1' (Using password: NO)

what i changed the getConnection parameters to : "jdbc:mysql://localhost:3306/Books ?user=foo password=foo" but now getting the upper error. any help would be great. thank you

This could just be a typo in this post but the problem with the line of code is you are missing an &. so, your code should be "jdbc:mysql://localhost:3306/Books ?user=foo &password=foo"
Hope that helps.
 
LiL Kunji
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you greg but i'm still not getting anywhere. here is most (about half so brackets won't match) of the code minus some stuff but to give u an idea of what i'm doing and the error when i try to connect:
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TableDisplay extends JFrame {
private Connection connection;
private JTable table;

public TableDisplay()
{


try {
Class.forName( "org.gjt.mm.mysql.Driver" );
connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/mysql ?user=root & password=foo");
}
catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
System.exit( 1 );
}
catch ( SQLException sqlex ) {
System.err.println( "Unable to connect" );
sqlex.printStackTrace();
}
getTable();
setSize( 450, 150 );
show();
}
private void getTable()
{
Statement statement;
ResultSet resultSet;

try {
String query = "show tabels from mysql";
statement = connection.createStatement();
resultSet = statement.executeQuery( query );
displayResultSet( resultSet );
statement.close();
}
catch ( SQLException sqlex ) {
sqlex.printStackTrace();
}
}
private void displayResultSet( ResultSet rs )
throws SQLException
{

boolean moreRecords = rs.next();

if ( ! moreRecords ) {
JOptionPane.showMessageDialog( this,
"ResultSet contained no records" );
setTitle( "No records to display" );
return;
}

error:
Unable to connect
java.sql.SQLException: Invalid authorization specification: Access denied for us
er: 'root @127.0.0.1' (Using password: NO)
at org.gjt.mm.mysql.MysqlIO.init(Unknown Source)
at org.gjt.mm.mysql.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at TableDisplay.<init>(TableDisplay.java:19)
at TableDisplay.main(TableDisplay.java:135)
Exception in thread "main" java.lang.NullPointerException
at TableDisplay.getTable(TableDisplay.java:46)
at TableDisplay.<init>(TableDisplay.java:32)
at TableDisplay.main(TableDisplay.java:135)

please help!!! thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic