Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » jdbc connector
jdbc connector [message #250023] Wed, 05 December 2007 13:00 Go to next message
Eclipse UserFriend
Originally posted by: aei_export.hotmail.com

Hi. after 24 hours non stop trying to put the jar file to work, i want to
cry.
I have followed *every* answer i found in the internet forums. Before your
advice please let me tell you what i did.
I pasted the file in the jre/lib/ext,jre/lib/jdk/lib/ext/jdk/lib folders.
I tried from the properties of my project to add it to the build path as
an external jar.
I CAN import it and i see it as a package when i write com.mysql.jdbc .
But Class.forName ALWAYS doesn't compile.

I repeat, i can import com.mysql.jdbc.* but i can't class.forName it.

Please answer as you would answer to someone with an iq of zero. Don't
assume anything, but please try to help.

thanks
Re: jdbc connector [message #250028 is a reply to message #250023] Wed, 05 December 2007 15:42 Go to previous messageGo to next message
Eclipse UserFriend
aris wrote:
> Hi. after 24 hours non stop trying to put the jar file to work, i want
> to cry.

Understandable under the circumstances.

> I have followed *every* answer i found in the internet forums. Before
> your advice please let me tell you what i did.
> I pasted the file in the jre/lib/ext,jre/lib/jdk/lib/ext/jdk/lib folders.

AFAIK it doesn't matter where the jar file goes, just so long as it's
accessible (and you know where it is). I put mine in a libraries folder
that's unrelated to the JRE and JDK installations.

> I tried from the properties of my project to add it to the build path as
> an external jar. I CAN import it and i see it as a package when i write
> com.mysql.jdbc .

Just to be sure we're talking about the same thing, the jar file in
question is mysql-connector-java-5.0.8-bin.jar (give or take the version
number)?

In my code, at least, I don't import anything from the jar (at least not
with an import statement). The only places that shows up is in the
Class.forName line: Class.forName("com.mysql.jdbc.Driver"). What I do
import is a bunch of java.sql.* stuff, including java.sql.DriverManager.

> But Class.forName ALWAYS doesn't compile.
>
> I repeat, i can import com.mysql.jdbc.* but i can't class.forName it.

What happens when you try? Are you specifying the .Driver part in the
argument to forName?
>
> Please answer as you would answer to someone with an iq of zero.

In my world, that makes you a dean or higher. :-)

> Don't
> assume anything, but please try to help.

It might help if you posted just the database-related lines of your
code, so we can see what you're doing. If it helps, here's an
abbreviated list of what works for me:

// these are the only DB-related imports
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
// ...
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
//whimper
}
// if you get here, the driver is at least loaded
Statement stmt;
Connection conn;
// the database server is on the development machine (hence localhost)
String creq = "jdbc:mysql://localhost/" + db; // db holds the database name
try {
conn = DriverManager.getConnection(creq, user, pw);
// user and pw are what you think they are
stmt = conn.createStatement();
} catch (SQLException e) {
// whimper
}
// if you get here, you're connected to the DB and you can use stmt
// to create and execute SQL queries

HTH,
Paul
Re: jdbc connector [message #250036 is a reply to message #250028] Thu, 06 December 2007 05:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aei_export.hotmail.com

Paul A. Rubin wrote:

> Just to be sure we're talking about the same thing, the jar file in
> question is mysql-connector-java-5.0.8-bin.jar (give or take the version
> number)?

yes this is the file

> What happens when you try? Are you specifying the .Driver part in the
> argument to forName?
> It might help if you posted just the database-related lines of your
> code, so we can see what you're doing.

import java.sql.*;

public void main()
{
Class.forName("com.mysql.jdbc.Driver");
}

this results in classnotfound exception.
if i write in the program com. the the completion knows that there is
mysql->jdbc etc.
That's the weird thing. I also can import com.mysql.jdbc.*; and that means
that the jar is accessible from my program. Any ideas? It's driving me
crazy.

aris
Re: jdbc connector [message #250044 is a reply to message #250036] Thu, 06 December 2007 09:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

aris wrote:

> import java.sql.*;
>
> public void main()
> {
> Class.forName("com.mysql.jdbc.Driver");
> }
>
> this results in classnotfound exception.
> if i write in the program com. the the completion knows that there is
> mysql->jdbc etc.
> That's the weird thing. I also can import com.mysql.jdbc.*; and that
> means that the jar is accessible from my program. Any ideas? It's
> driving me crazy.

Build path and runtime classpath are separate. Since you can write code
that references the JDBC classes, you must have the JARs on the build
path correctly. The fact that those classes can't be found at runtime
means the JARs are not on the runtime classpath of your application. You
probably need to edit the Launch configuration of your app to include
the necessary JARs.

Hope this helps,
Eric
Re: jdbc connector [message #250047 is a reply to message #250044] Thu, 06 December 2007 11:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aei_export.hotmail.com

This doesn't seem to work either.

Please if anyone kind-hearted could take a look at this snapshot of my
eclpise:

http://www.megafileupload.com/en/file/27263/jdbc-JPG.html
(click on the download file to see it)

I have the mysql connector EVERYWHERE.
Excuse me, i'm not a whinnie but i have read almost everything there is on
the internet and i'm a professional programmer for years. This is the
first time that nothing seems to work for no reason, when everybody else
can do it..

thanks in advance

aris
Re: jdbc connector [message #250051 is a reply to message #250047] Thu, 06 December 2007 11:35 Go to previous messageGo to next message
Eclipse UserFriend
aris wrote:
> This doesn't seem to work either.
>
> Please if anyone kind-hearted could take a look at this snapshot of my
> eclpise:
>
> http://www.megafileupload.com/en/file/27263/jdbc-JPG.html
> (click on the download file to see it)
>
> I have the mysql connector EVERYWHERE.
> Excuse me, i'm not a whinnie but i have read almost everything there is
> on the internet and i'm a professional programmer for years. This is the
> first time that nothing seems to work for no reason, when everybody else
> can do it..
>
> thanks in advance

I took a look at the screen shot. You've got the run configuration open
showing that the jar is on the class path, but you're problem is not
with the run time class path, it's with compilation. The package
explorer shows the jar visible, but what's not in the screen shot is the
build path. If you right-click on the package icon in the package
explorer, then click Build Path -> Configure Build Path, does the jar
file show up in the Libraries tab (or anywhere else)?

Incidentally, on the theory that I might use the MySQL drivers in more
than one project, I set them up as a user library. I navigated to
Window -> Preferences -> Java -> Build Path -> User Libraries, clicked
New and supplied a name (MySQL Connector J in my case), selected the new
library, clicked Add JARS and pointed to the mysql jar file. (You can
also attach source and javadoc locations by highlighting those and
clicking edit.)

If you haven't done so, you might try making the connector jar a user
library and then specifying it in the build path that way.

If none of this helps (you already have it on the build path, as a
library, sanctioned by the U.N., ...), the only other thing I can
suggest is to expand the com.mysql.jdbc package (visible in your screen
shot) and make sure that it contains Driver.class. You've apparently
got a more recent version than I do. One would assume that it's intact,
but a check can't hurt.

/Paul
Re: jdbc connector [message #250055 is a reply to message #250047] Thu, 06 December 2007 11:39 Go to previous messageGo to next message
Eclipse UserFriend
Wait a second! I just took a closer look at that screen shot. The
problem is NOT that Eclipse can't find your MySQL driver jar: it's that
you didn't surround the Class.forName command with a try/catch block.
It doesn't matter that you and Eclipse both see the jar: Class.forName
will throw a ClassNotFound exception at run time if it doesn't find the
class file, and you *must* either catch that exception or throw it to a
higher level. Apparently you're doing neither.

/Paul
Re: jdbc connector [message #250059 is a reply to message #250055] Thu, 06 December 2007 11:46 Go to previous message
Eclipse UserFriend
Originally posted by: aei_export.hotmail.com

This is insane, but I have my *ss covered. That's why I sais please
respons as if i have an iq below zero.

Dear friend, THANK YOU IMMENSLY!!!!!!!!!!!!

And excuse me.....!!

aris
Previous Topic:Logical structure
Next Topic:Trying to compare two types for subtype compatibility
Goto Forum:
  


Current Time: Sun Apr 20 19:32:27 EDT 2025

Powered by FUDForum. Page generated in 0.04560 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top