Java ODBC数据源(未定义的符号:SQLAllocEnv) [英] Java ODBC Data Source ( undefined symbol: SQLAllocEnv )

查看:264
本文介绍了Java ODBC数据源(未定义的符号:SQLAllocEnv)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Java代码。此代码的目的是为远程MySQL数据库ProductionDb(我的/etc/odbc.ini文件中定义的数据源)建立连接

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());
        }
    }

}

/ etc / odbc.ini文件是:

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

顺便说一句 - 我使用的是Java 7和Ubuntu:

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 ?

PS顺便说一下我运行sudo apt-get install unixodbc-dev,sudo apt-get install libmyodbc和sudo apt- get install libmysql-java :-)

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 :-)

更新:

我也有尝试了下面的一个回复(Benny Hill)中建议的想法:使用/etc/odbcinst.ini以及/etc/odbc.ini。仍然无法正常工作,我收到相同的错误消息。

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

附加说明:

我可以使用R
编程语言成功使用此ODBC数据源。

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


推荐答案

听起来像是缺少或不匹配的库。尝试调试ldd处理。

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

首先,检查

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

说,是否存在所有列出的依赖项?

says, do all listed dependencies exist?

然后,尝试设置LD_DEBUG并再次启动Java程序,以查看加载程序调试。

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

$ export LD_DEBUG=all
$ java Test

这篇关于Java ODBC数据源(未定义的符号:SQLAllocEnv)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆