Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to Database from Linux

Status
Not open for further replies.

Ziggurat

Programmer
Jun 6, 2001
81
GB
Dear All,

I hope that this is the right forum.
My apologies if it is not.

Can anyone tell me what I am doing wrong with my database connection.

First some history:-

On RedHat 9.0 I have added the packages for:-
Mysql
unixODBC
myODBC

I tested that mysql was running

I have modified the ini files
odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver =/usr/libg/libmyodbc.so
FileUsage =1

odbc.ini
[Mic]
Description =MySQL database test
Driver =MySQL
Server =localhost
Database =test
Port =3306

I then tested using :-
isql Mic

and it was OK.

Then when I tried to run a java program to test the connection, It failed on the line
Connection con = DriverManager.getConnection("jdbc:eek:dbc:Mic");

throwing a NullPointerException.

Does anyone have any idea what is the problem ?

Or can someone point me to a location where I can find out how to create Data Source Names in Linux, test and connect to them.

Thank you in advance.


#
###
#####
#######
Ziggurat
 
Your connection String for mysql is incorrect. It should be like :

Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/test");

You will obviously need the relevant jar file in your Java CLASSPATH (jar file is named usually like "mysql-connector-java-3.0.9-stable-bin.jar").

--------------------------------------------------
Free Database Connection Pooling Software
 
Thank you for your prompt reply sedji

I am sorry that I might not have made myself clear on this point.

I understand that I am not using the my MySQL driver for the database connection.
My point is that I am trying to understand how to set up the ODBC connection to the database so that I will be able to use it for various databases just by adding the appropriate data source name to the list.

Do you have any idea how I can set this up for ODBC connection.

#
###
#####
#######
Ziggurat
 
Sorry, thought you wanted to connect via the MySQL JDBC driver.

I've never set up the ODBC driver explicitly on Linux, but the documentation looks pretty good -

Have you downloaded the appropriate ODBC driver from her :


And read the installation guide here :


--------------------------------------------------
Free Database Connection Pooling Software
 
Hi sedj

Thanks again for taking the time to answer my message.

I have already installed the odbc connector (See the line Driver =/usr/libg/libmyodbc.so in the odbcinst.ini) and I have read the MySQL mailing list.

I found a similar question to the one that I am asking
(Nov 28 2002)

and the answer given is the same as the one that you suggested. (I know that the [mysql-connector-java-3.0.9-stable-bin.jar] method works as I have already set it up.) My problem is that I would like to create an ODBC version.

If you have any other suggestions please let me know.

THX

#
###
#####
#######
Ziggurat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top