aspose file tools*
The moose likes JDBC and the fly likes MySQL db - migrating from Access (but where is the driver?!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL db - migrating from Access (but where is the driver?!)" Watch "MySQL db - migrating from Access (but where is the driver?!)" New topic
Author

MySQL db - migrating from Access (but where is the driver?!)

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi All,

I have recently migrated from MS-Access to MySQL (recommendation of this forum) anyway, it works fine with my IDE (conn to db is working) but not when I "JAR" the java class and run it from the command line (I get: com.mysql.jdbc.Driver).

Now, when I used MS Access db I 'showed' the computer that the database I'm talking about is: Start-->Control Panel-->Administrative tools-->Data Source(ODBC) and then configuring it with the System DSN.

Questions:
1. How do I do that in MySql ?? ? ? (I don�t have the driver?! There�s only SQL Server)
2. How does the computer 'know' which database I'm talking about???

Thanks for any help
myriah wind
Greenhorn

Joined: Mar 04, 2005
Posts: 14
com.mysql.jdbc.Driver
is the class used for jdbc with MySQL dbms you can get the archive and documentation at

http://dev.mysql.com/downloads/connector/
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
I am using Connector/J:

and it works fine - but only when i compile and run it with my IDE (Eclipse) but when i export the project to a JAR file and try to run it from the command line i get: com.mysql.jdbc.Driver

any idea?


BTW, how does eclipse compile it and run it ok?
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
You need to have a manifest file in your JAR with a CLASSPATH argument that points to the Connector/J jar file. You should also be able to put the Connector/J jar file on your system CLASSPATH, but the manifest is a more portable way.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Thank you Steven,

I'm doing this:
java -cp mysql-connector-java.jar com.agm.main.GTP

if I click on my command line: set classpath, I get:
classpath=.;c:\mysql-connector-java.jar

so I take it the classpath is fine...still it runs only on my IDE not on the command line. Please help...
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
hmmm, Could you post the errors you get when running from the command line?
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
I ran a simple program called TestMysql that runs on my IDE:
it is:

public class TestMysql
{
public static void main(String args[]) {
try {
/* Test loading driver */

String driver = "com.mysql.jdbc.Driver";

System.out.println( "=> loading driver:" );
Class.forName( driver ).newInstance();;
System.out.println( "OK" );

/* Test the connection */

String url = "jdbc:mysql://localhost/test";

System.out.println( "=> connecting:" );
DriverManager.getConnection( url, "root", "cardinal" );
System.out.println( "OK" );
}
catch( Exception x ) {
x.printStackTrace();
}
}
}


on the command line I get:



C:\Documents and Settings\Peter\Desktop\t>java TestMysql
=> loading driver:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at TestMysql.main(TestMysql.java:12)
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I can't think of anything it can be other than a classpath issue, sorry.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Steven Thanks a lot!!!

you mention classpath and that's the KEY!!! I got it. I used the wrong connector.

THANKS it works...one question however, say I want to share the database on a network so other computers can access my databsae, how do i do that???

In MS access I used the
Start-->Control Panel-->Administrative tools-->Data Source(ODBC) and then configuring it with the System DSN.

Do you know how to do it with MySQL???

Thanks
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
With MySQL it is already shared, you only have to set up a user with the proper access. I think the MySQL Administrator tool will do that. MySQL also distinguishes localhost users from external users so make sure you set up the right kind of user.

Glad to hear you got things working.

P.S. With the Access DB you were using, were you connecting to that with a Java app? If so what were you using? Also are you using the same table setup or are they different and how did you move the data over? I only ask because I need to move data from an Access DB over to a MySQL DB, but the table structure is very different (I swear the old Access DB was setup by a monkey ).
[ March 05, 2005: Message edited by: Steven Bell ]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Steven, Thank you from New York
 
 
subject: MySQL db - migrating from Access (but where is the driver?!)