LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to configure MySql ODBC (https://www.linuxquestions.org/questions/linux-software-2/how-to-configure-mysql-odbc-452922/)

julian.osorio 06-08-2006 02:36 PM

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

rylan76 06-09-2006 03:02 AM

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!


All times are GMT -5. The time now is 12:43 PM.