我有以下Java代码.此代码的目的是建立连接
到远程MySQL数据库ProductionDb(我的/etc/odbc.ini文件中定义的数据源).
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文件是:
$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:
$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
当我尝试运行我的程序时,我收到以下错误:
$java Test
java: symbol lookup error: /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libJdbcOdbc.so: undefined symbol: sqlAllocEnv
有谁知道我为什么会收到这个错误?
这有什么不对?
P.S顺便说一下我运行sudo apt-get install unixodbc-dev,sudo apt-get install libmyodbc和sudo apt-get install libMysqL-java 原文链接:https://www.f2er.com/mysql/434002.html