java odbc,Java ODBC数据源(未定义的符号:SQLAllocEnv)

I have the following Java code. Purpose of this code is to establish a connection

to a remote MySQL database ProductionDb ( a data source defined in my /etc/odbc.ini file ).

import java.sql.*;

import java.util.*;

import java.io.*;

public class Test {

public static void main(String[] args) {

try {

Connection conn = null;

PreparedStatement s = null;

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

Class.forName(driver).newInstance();

conn = DriverManager.getConnection("jdbc:odbc:ProductionDb");

} catch (Exception ex) {

System.out.println(ex.getMessage());

}

}

}

The /etc/odbc.ini file is:

$ cat /etc/odbc.ini

[ProductionDb]

Driver = /usr/lib/odbc/libmyodbc.so

Description = Production Database

Server = [ hidden ]

Port = 3306

User = [ hidden ]

Password = [ hidden ]

Database = ProductionDb

By the way - I am using Java 7 and Ubuntu :

$java -version

java version "1.7.0_09"

Java(TM) SE Runtime Environment (build 1.7.0_09-b05)

Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

$lsb_release -a

No LSB modules are available.

Distributor ID: Ubuntu

Description: Ubuntu 11.04

Release: 11.04

Codename: natty

When I try to run my program I get the following error:

$java Test

java: symbol lookup error: /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libJdbcOdbc.so: undefined symbol: SQLAllocEnv

Does anyone know why I get this error ?

What is wrong here ?

P.S By the way I did run sudo apt-get install unixodbc-dev , sudo apt-get install libmyodbc and sudo apt-get install libmysql-java :-)

UPDATE:

I have also tried the idea suggested in one of the replies below ( by Benny Hill ) : to use the /etc/odbcinst.ini as well as /etc/odbc.ini. Still doesn't work and I get the same error message.

$ cat /etc/odbc.ini

[ProductionDb]

Driver = MySQL Driver

Description = Production Database

Server = [ hidden ]

Port = 3306

User = [ hidden ]

Password = [ hidden ]

Database = ProductionDb

$ cat /etc/odbcinst.ini

[MySQL Driver]

Driver = /usr/lib/odbc/libmyodbc.so

ADDITIONAL NOTE:

I can use this ODBC data source successfully from the R

programming language.

> library(odbc)

> con = odbcConnect("ProductionDb")

> con

RODBC Connection 1

Details:

case=nochange

DSN=ProductionDb

解决方案

Sounds like a missing or mismatched library. Try to debug the ldd processing.

First, check what

$ ldd /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libJdbcOdbc.so

says, do all listed dependencies exist?

Then, try setting LD_DEBUG and and start your Java program again, to see the loader debug.

$ export LD_DEBUG=all

$ java Test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值