-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Rhino wrote:
> Scott, > > I'm going to put this reply into the list rather than answer it offline. I > hope that's okay with you. If I answer you offline, only you will know the > answer but if I answer on the mailing list, everyone who monitors the list - > and anyone who checks the archives in the future! - can benefit. > > The rest of my reply is interspersed in your note.... > > Rhino > > ----- Original Message ----- > From: "Scott D. Spiegler" <[EMAIL PROTECTED]> > To: "Rhino" <[EMAIL PROTECTED]> > Sent: Wednesday, June 16, 2004 6:14 PM > Subject: Re: Why can't I make a connection? > > >> >> > 1. Have you installed a MySQL Java driver and is it >> > accessible to the >> > program? >> >> That's what I am not sure about. I placed the drivers >> in the location specified by the documentation or at >> least I think I have. Where do you usually place them? >> I followed this course of action from the docs: "copy >> the "com" and "org" subdirectories and all of their >> contents to anywhere you like, and put the directory >> holding the "com" and "org" subdirectories in your >> classpath". I also added >> > "D:\mysql-connector-java\mysql-connector-java-3.1.1-alpha\mysql-connector-ja > va-3.1.1-alpha-bin.jar;" >> to my CLASSPATH variable under >> Start->System->Advanced->Environment Variables. Is >> that correct? >> > I'm assuming you assigned that path to the CLASSPATH environment variable. > If not, you should have ;-) I'm also assuming that the driver you are using > is appropriate for the version of MySQL you are using. > > Since the classpath approach doesn't work for you, I'm going to suggest > another approach, rather than trying to work out why your classpath isn't > working. > > I have lately started putting my database drivers in the extensions library > of the JRE and it's working very well. You can read about this technique in > the Java Tutorial in the trail entitled "The Extension Mechanism". I'm not > sure which version of Java you are using or whether you're familiar with the > Java Tutorial but I found it very useful in my early days in Java and I > still use it from time to time to learn new things. > > You can see the Java Tutorial online at > http://java.sun.com/docs/books/tutorial/. You can see "The Extension > Mechanism" in the Specialized Trails area of that page. (The Java Tutorial > can also be downloaded, which is very handy if you have a slow connection.) > > Quoting from this trail: > Extensions are groups of packages and classes that augment the Java platform > through the extension mechanism. The extension mechanism enables the > runtime environment to find and load extension classes *without the > extension classes having to be named on the class path* [emphasis added]. In > that respect, extension classes are similar to the Java platform's core > classes. That's also where extensions get their name -- they, in effect, > extend the platform's core API. [end citation] > > In a nutshell, if you put your MySQL driver file in the JRE/lib/ext > directory, your programs should be > able to see it and use it without having to mess around with your classpath. > > Unfortunately, *finding* the (correct) extensions directory can be a can of > worms, particularly if you have multiple versions of Java on your system. > For instance, I installed the SDK for Java 1.4.1 on my main development > machine which would suggest that I have only a single JRE library. In fact, > I have FOUR of them. I have: > a) the JRE for Java 1.4.1 which I installed automatically when I installed > the 1.4.1 SDK. > b) a second JRE that is standalone, i.e. not part of an SDK. I honestly > don't recall how that one got there any more. > c) a JRE for Java 1.1.8. > d) a JRE for Java 1.2.2. > > The latter two JREs are there because I also have DB2 installed on this > machine and it comes with two full Java SDKs, 1.1.8 and 1.2.2, each of which > include JREs. > > You could be in the same sort of situation, not necessarily through any > action you took consciously. So which extension library do you use for your > MySQL drivers? Well, in theory, you could reason it all out but I'm going to > suggest a "brute force" method that will be much faster and shouldn't do any > harm: > 1) find all of your JREs > 2) put the MySQL driver in the extension library (JRE/lib/ext) of ALL of > them > 3) once you get your program working, remove the MySQL driver from the > "extra" extension libraries one at a time, ensuring that your program still > works before attempting to remove the next one. If the program stops > working, you've removed the wrong copy; put it back and verify that the > program still works. Eventually, you will only have one MySQL driver and it > will be exactly where it ought to be. > > With any luck though, you only have one JRE: then all you need to do is put > your MySQL driver in JRE/lib/ext and you should be "good to go". Please don't do this if you want to save time upgrading later on ;) I've had more bug reports from users who _think_ they're using one version of the JDBC driver, but they're using one from JRE/lib/ext, because that path takes 'precedence', and it takes forever and a day to figure out where it is (especially if they're just using 'java' with no absolute path to launch the vm). Hopefully this will all be cleared up with JDBC-4.0, which has some 'ease-of-development' stuff being worked on. If you're running a Java program, you can pass the CLASSPATH _explicitly_ in the command-line: java -classpath foo.jar;baz.jar;. mypackage.MyClass .... (of course use ':' instead of ';' if you're on Unix or something 'unixy') > >> > It sounds a little bit as if this is your first >> > Java/MySQL program. >> >> Yes, it is. Once I make the initial connection, I >> think I should know where to go from there, but I am >> not sure that I am telling my app where to go to find >> the drivers. >> > I think you're probably right. I've always found that first programs were > extremely crucial for developing the confidence that it takes to proceed and > succeed with a given programming technique. > > Good luck and let us know if my suggestion doesn't work for you; perhaps > someone else can suggest a better approach! Looking at your code in your post, it appears that you never 'register' the driver with the java.sql.DriverManager. You either need to pass it on the Java VM's command-line when you launch your program (-Djdbc.drivers=com.mysql.jdbc.Driver), or alternatively, do a Class.forName("com.mysql.jdbc.Driver) in your class before you attempt to call DriverManager.getConnection(....). See http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DriverManager.html for more information ;) Regards, -Mark - -- Mr. Mark Matthews MySQL AB, Software Development Manager, J2EE and Windows Platforms Office: +1 708 332 0507 www.mysql.com MySQL Guide to Lower TCO http://www.mysql.com/it-resources/white-papers/tco.php -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFA0OhTtvXNTca6JD8RAsJlAJ4hHlPE751v/dS6mt7l+y1yLu3uoQCffP7l OvRyWuk6OTD120jjxEAFoPI= =0uDg -----END PGP SIGNATURE----- -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]