File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm, Could you post the errors you get when running from the command line?
 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't think of anything it can be other than a classpath issue, sorry.
 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven, Thank you from New York
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic