LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-08-2006, 03:36 PM   #1
julian.osorio
Member
 
Registered: Apr 2006
Location: Bogota,Colombia,South America
Distribution: SuSE, Slackware
Posts: 30

Rep: Reputation: 15
How to configure MySql ODBC


Hello everyone

im interested to work with Java and MySql
but i don`t know how to configure the odbc

i have done this

[julian@localhost ~]$ odbc_config
Usage: odbc-config
[--prefix]
[--exec-prefix]
[--include-prefix]
[--lib-prefix]
[--bin-prefix]
[--version]
[--libs]
[--static-libs]
[--libtool-libs]
[--cflags]
[--odbcversion]
[--longodbcversion]
[--odbcini]
[--odbcinstini]
[julian@localhost ~]$ odbc_config --version
2.2.11

and looked for the myodbc files
in /usr/lib64

there is an odbc.ini
this was in blank but i used

ODBC Data Sources]
myodbc = MyODBC 2.50 Driver DSN
myodbc3 = MyODBC 3.51 Driver DSN

[myodbc]
Driver = /usr/lib64/libmyodbc.so
Description = MyODBC 2.50 Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =

[myodbc3]
Driver = /usr/lib64/libmyodbc3.so
Description = MyODBC 3.51 Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =

[Default]
Driver = /usr/local/lib/libmyodbc3.so
Description = MyODBC 3.51 Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =

what i have to do next???

waiting for an answer
 
Old 06-09-2006, 04:02 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,542

Rep: Reputation: 101Reputation: 101
Well, Java and MySQL works just fine via ODBC in a Java app I recently wrote. I made no special configurations on the Java or MySQL side, I just installed a binary of MySQL (4.0.12), downloaded the latest Java ODBC driver from the MySQL site, and it worked. Note that the MySQL ODBC driver needs to be somewhere where the Java compiler will be able to find it. Some sample Java code:

import java.sql.*;

.
.
.
static String mysql_serverName = "your.server.name";
static String mysql_mydatabase = "your.db.name";
static String mysql_username = "your_mysql_user_name";
static String mysql_password = "your_password";

static public Connection connect_to_db()
/*
Connect to the target database
*/
{
try
{
connection = null;

String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);

String url = "jdbc:mysql://" + mysql_serverName + "/" + mysql_mydatabase;

connection = DriverManager.getConnection(url,mysql_username,mysql_password);
}

catch (ClassNotFoundException cne)
{
System.out.println("Class not found exception in connecting to db.");
System.out.println(cne.getMessage());
cne.printStackTrace();

connection = null;
}

catch (SQLException sqle)
{
System.out.println("SQL Exception in connecting to db.");
System.out.println(sqle.getMessage());
sqle.printStackTrace();

connection = null;
}

return connection;
}

And here's how I execute a query:

public void buildProjectList(MutableList targetList)
/*
Build the list of available projects on the DSS.
*/
{
connection = connect_to_db();

//Results column strings
String project_id;
String project_name = "";

int item_idx = -1;
int default_idx = -1;

if (connection == null)
{
System.out.println("Unable to create JDB connection to db. Please contact Polar Software Support.");
}//if (connection == null)

else

{
int default_set_flag;

try
{
Statement stmt = connection.createStatement();

ResultSet rs = stmt.executeQuery("select * from dss_user_set where active=1 order by name asc");
while (rs.next())
{
item_idx++;

project_id = rs.getString("id");
project_name = rs.getString("name");

targetList.getContents().addElement(project_name);
}//while (rs.next())

//Preselect the first project as the default target project
targetList.setSelectedIndex(0);

targetList.setFixedCellWidth(list_cellWidth);

connection.close();
}//try

catch (SQLException sqle)
{
System.out.println("SQL Exception while building project group list.");
System.out.println(sqle.getMessage());
sqle.printStackTrace();
}//try
}//if (connection == null)
}

All the above worked perfectly with no special configuration of MySQL or Java, as I said I just downloaded the MySQL -> Java ODBC .jar off the MySQL site, and used the above code.

Hope this helps!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL ODBC driver fails when trying to add a DSN to MySQL banjoman Linux - Software 0 01-24-2005 10:59 AM
ODBC/MySQL/OpenOffice linuxfond Linux - Newbie 1 05-09-2004 05:27 PM
MySQL + ODBC + C programming qusestion sleepymish Programming 0 01-13-2004 10:52 AM
ODBC connection to MySQL darius Linux - Software 2 09-29-2003 07:40 PM
ODBC driver for MySql baburaj General 1 06-29-2002 11:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration