在GNU/Linux上的Java数据库连接。

时间:2021-03-02 19:29:17

I'm having a Java class and I'm really new to Database Connectivity.. My professor and everyone else on this class use Windows and an Access Database, and I'm the only one using GNU/Linux with a MYSQL Database.
Now as you know Windows programmers use ODBC, but as I searched, I got that it's only for windows. I found a Unix/Linux ODBC from easysoft but it doesn't support MYSQL
Is there any Open-Source ODBC you know of that supports MYSQL?
Moreover how should I use this Driver in java?
Couldn't find neither a documentation nor a tutorial for GNU/Linux..

我有一个Java类,我对数据库连接非常陌生我的教授和其他所有人都使用Windows和Access数据库,而我是唯一一个使用GNU/Linux和MYSQL数据库的人。现在,正如您所知道的,Windows程序员使用ODBC,但当我搜索时,我发现它只适用于Windows。我从easysoft找到了一个Unix/Linux ODBC但它不支持MYSQL有什么开源的ODBC支持MYSQL吗?此外,我应该如何在java中使用这个驱动程序?无法找到GNU/Linux的文档和教程。

3 个解决方案

#1


1  

Just install MySQL Connectors from this link

只需从这个链接安装MySQL连接器。

Code to connect to mysql via jdbc :

通过jdbc连接到mysql的代码:

import java.lang.*;
import java.sql.*;

public class Demo {
    public static void main(String[] args){
        try{
            Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?" + "user=test&password=123456");
        }catch(SQLException ex){
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
        }catch(Exception ex){
            System.out.println("Exception: " + ex.getMessage());
        }
    }                                             
}

#2


1  

MySQL provides both ODBC and JDBC drivers. Check their web site. Documentation is also provided.

MySQL同时提供ODBC和JDBC驱动程序。检查他们的网站。文档也提供。

#3


0  

Don't worry about ODBC drivers. You just need the MySQL JDBC driver.

不要担心ODBC驱动程序。您只需要MySQL JDBC驱动程序。

https://dev.mysql.com/downloads/connector/j/

https://dev.mysql.com/downloads/connector/j/

Here is also some info on setting up the connection:

这里还有一些关于建立联系的信息:

What is the MySQL JDBC driver connection string?

什么是MySQL JDBC驱动程序连接字符串?

#1


1  

Just install MySQL Connectors from this link

只需从这个链接安装MySQL连接器。

Code to connect to mysql via jdbc :

通过jdbc连接到mysql的代码:

import java.lang.*;
import java.sql.*;

public class Demo {
    public static void main(String[] args){
        try{
            Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?" + "user=test&password=123456");
        }catch(SQLException ex){
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
        }catch(Exception ex){
            System.out.println("Exception: " + ex.getMessage());
        }
    }                                             
}

#2


1  

MySQL provides both ODBC and JDBC drivers. Check their web site. Documentation is also provided.

MySQL同时提供ODBC和JDBC驱动程序。检查他们的网站。文档也提供。

#3


0  

Don't worry about ODBC drivers. You just need the MySQL JDBC driver.

不要担心ODBC驱动程序。您只需要MySQL JDBC驱动程序。

https://dev.mysql.com/downloads/connector/j/

https://dev.mysql.com/downloads/connector/j/

Here is also some info on setting up the connection:

这里还有一些关于建立联系的信息:

What is the MySQL JDBC driver connection string?

什么是MySQL JDBC驱动程序连接字符串?