Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2006

Tip: Looking for answers? Try searching our database.

Possible JDBC installation or usage problem in OS X

Thread view: 
barry_normal - 20 Dec 2006 10:03 GMT
Hello there,

I'm having a terrible time trying to use the JDBC in os x.

What I want to do is use a program written in java and executed on my
mac to connect to a database on my website and INSERT a huge amount of
data. I have to do this as the upload limit on the web hosting is 2MB
and I've got a GB of data...

So, I've downloaded and extracted the jdbc mysql driver:
mysql-connector-java-3.1.14

Then I've opened my etc/profile file and added the location to the
classpath like this:

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/mysql-connector-java-3.1.14/mysql-connector-java-3.1.14-bin.jar"
export PATH  - This might be the problem but I couldn't find an
explicit example of how to do this...

Then I connect to the DB like this:

...
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception ex) {
// handle the error
}

   String conStr = "jdbc:mysql://http://mywebsite.net/myDatabase";

try {
Connection conn = DriverManager.getConnection(conStr, "user", "pass");
System.out.println("connected");
}
...

The result is always this:

SQLException: No suitable driver
SQLState: 08001
VendorError: 0

I'm a long way from being an expert so this is totally baffling me. Any
help would be great.

All the best
B
Ian Wilson - 20 Dec 2006 13:23 GMT
> I'm having a terrible time trying to use the JDBC in os x.
>
[quoted text clipped - 4 lines]
> export PATH  - This might be the problem but I couldn't find an
> explicit example of how to do this...

CLASSPATH is not the same as PATH.
barry_normal - 20 Dec 2006 13:37 GMT
Hi Ian, thanks for that,

So should I just alter that same file to include the following?

CLASSPATH="/usr/mysql-connector-java-3.1.14/mysql-
connector-java-3.1.14-bin.jar"
export CLASSPATH

Does this make it the classpath Java apps will use?

Cheers
B

> > I'm having a terrible time trying to use the JDBC in os x.
> >
[quoted text clipped - 6 lines]
>
> CLASSPATH is not the same as PATH.
Ian Wilson - 20 Dec 2006 16:07 GMT
A: Because it is harder to follow.

Q: Why shouldn't I post my reply above the original text?

(top-posting corrected)

>>> I'm having a terrible time trying to use the JDBC in os x.
>>>
[quoted text clipped - 11 lines]
> CLASSPATH="/usr/mysql-connector-java-3.1.14/mysql-
> connector-java-3.1.14-bin.jar" export CLASSPATH

Yes. Why didn't you just try it?

> Does this make it the classpath Java apps will use?

Usually.

Google for "Java classpath" then follow the sun.com or Roedy Green
links. Google is useful, I recommend you try it occasionally :-)
barry_normal - 20 Dec 2006 16:36 GMT
> A: Because it is harder to follow.
>
[quoted text clipped - 26 lines]
> Google for "Java classpath" then follow the sun.com or Roedy Green
> links. Google is useful, I recommend you try it occasionally :-)

Hello Ian,

Well, I tried googling but just couldn't find an explanation which was
more specific than just 'edit the file' not what to put in it.

Also, I wasn't sure if it could be some slight syntactical difference
which OS X exhibits in this department. All the instructions seem to
assume a Windows machine.

I did try putting the text in as above but that didn't have any effect.
Still getting the same message so I was unclear as to whether it needed
some other info in there or something I've no clue about at all.

Cheers!
B
Ian Wilson - 20 Dec 2006 17:39 GMT
>>> So should I just alter that same file to include the following?
>>>
>>> CLASSPATH="/usr/mysql-connector-java-3.1.14/mysql-
>>> connector-java-3.1.14-bin.jar" export CLASSPATH

> Well, I tried googling but just couldn't find an explanation which
> was more specific than just 'edit the file' not what to put in it.

I'm not familiar with OS X but since it is allegedly partly BSD based I
am sure you can persuade it to open a command shell and pretend it's Unix.

In which case something like this will work:

# MYSQLDIR=/usr/mysql-connector-java-3.1.14
# CLASSPATH=$MYSQLDIR/mysql-connector-java-3.1.14-bin.jar
# export CLASSPATH
# java myapp

(I only introduced MYSQLDIR to keep line lengths short for newsgroups)

> Also, I wasn't sure if it could be some slight syntactical difference
>  which OS X exhibits in this department. All the instructions seem to
>  assume a Windows machine.

The instructions for generic unix may be usable on OS X.

> I did try putting the text in as above but that didn't have any
> effect. Still getting the same message so I was unclear as to whether
> it needed some other info in there or something I've no clue about at
> all.

OK. Your original merror essage was
  SQLException: No suitable driver

I'm not familiar with MySQL but you might like to double check this line
in your code:

  String conStr = "jdbc:mysql://http://mywebsite.net/myDatabase";

The "http://" bit looks suspicious to me. I'd guess at

  String conStr = "jdbc:mysql://servername.eg.net:3306/myDatabase/";

Note the trailing slash!

Servername.eg.net is the name of the server and 3306 is whatever port
MySQL is configured for (I guess the default might be 3306?)

The next step is for you to write a 10-20 line Java program that simply
attempts to open a connection and close it again. If it doesn't work
post the whole Small Self-Contained/complete Compilable Example program
here.

I imagine MySQL includes such an example.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.