b

Java connect to microsoft access or mysql database

package main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

/**
*
* @author Josphat computertechie
*/
public class Table
{
static PreparedStatement pre =null;
static Connection conn=null;
/**
* Connect to database
*/
public static Connection ConnectDb(){
   

try{//Class.forName("com.mysql.jdbc.Driver");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection("jdbc:odbc:jos");
//Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/jos", "root", "");
return conn;
}catch (Exception e) {
return null;
}
}

/**
     *
     * @return
     * @throws Exception
     */
   
}
//for mysql just use the one with localhost

No comments:

Post a Comment

Found it interesting comment

Facebook autoposter