geekybedouin
geekybedouin

Reputation: 559

Java Database connectivity on GNU/Linux

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..

Upvotes: 1

Views: 4562

Answers (3)

Up_One
Up_One

Reputation: 5271

Just install MySQL Connectors from this link

Code to connect to mysql via jdbc :

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

Upvotes: 2

Roy Gabbard
Roy Gabbard

Reputation: 11

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

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?

Upvotes: 0

Jess Balint
Jess Balint

Reputation: 1697

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

Upvotes: 1

Related Questions