Sunday, July 10, 2011

Setting Java Connection with SQL

Java programming is quite utilized for web development and application systems. In my recent masteral project, we were asked to create a simple database application where MySQL was used as my back end.

We create the database in our SQL and create the link using the ODBC interface and driver. A use of Administrative Tools in Control Panel where ODBC   package was previously copied would allow us to connect with our database.

The program then below creates the connection.
[+/-] show/hide

package introtodbase;

import java.sql.*;
public class SetConnection {
public static Connection conn;
String url = "jdbc:odbc:music";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

public SetConnection(){
try {
conn = DriverManager.getConnection(url);
}catch (Exception e) {