关于JAVA用ODBC连接MYSQL的代码
下面是我想用ODBC连接MYSQL的代码,我想可能是“org.gjt.mm.mysql.Driver”,“jdbc:odbc:pk”这两个的问题,代码我是不是写错了,ODBC的驱动我也装了,名字是:mysql-connector-odbc-3.51.20-win32.msi
import java.sql.*;
class JDBCConnection {
static {
try {
Class.forName("org.gjt.mm.mysql.Driver");
}
catch (Exception e)
{
e.printStackTrace();
}
}
JDBCConnection()
{
try {
Connection conn = DriverManager.getConnection("jdbc:odbc:pk");
Statement stm=conn.createStatement();
ResultSet rst=stm.executeQuery("select * from dongdong");
while(rst.next())
{
String str1=rst.getString(1);
String str2=rst.getString(2);
System.out.println(str1+"\t\t"+str2);
}
rst.close();
System.out.println("连接数据库成功...");
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
class MainClass
{
public static void main(String[] args)
{
new JDBCConnection();
}
}