Mentions légales du service

Skip to content
Snippets Groups Projects
DBServiceImpl.java 3.35 KiB
Newer Older
Seungkeun Lee's avatar
Seungkeun Lee committed
/*
Seungkeun Lee's avatar
Seungkeun Lee committed
 * $Id$
Seungkeun Lee's avatar
Seungkeun Lee committed
 *
 * Copyright (C) XX, 2006
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

Seungkeun Lee's avatar
Seungkeun Lee committed
package fr.inrialpes.exmo.align.service;

import java.lang.ClassNotFoundException;
import java.lang.IllegalAccessException;
Seungkeun Lee's avatar
Seungkeun Lee committed

Seungkeun Lee's avatar
Seungkeun Lee committed
import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.ResultSet;
Seungkeun Lee's avatar
Seungkeun Lee committed
import java.sql.Statement;
import java.sql.SQLException;
Seungkeun Lee's avatar
Seungkeun Lee committed


public class DBServiceImpl implements DBService{
    int id = 0;
    Connection conn = null;
    static String IPAddress = "localhost";
    static String port = "3306";
Jérôme Euzenat's avatar
Jérôme Euzenat committed
    static String user = "adminAServ";
    static String database = "AServDB";
    String driverPrefix = "jdbc:mysql";
    Statement st = null;
Seungkeun Lee's avatar
Seungkeun Lee committed
    Cache cache = null;
Seungkeun Lee's avatar
Seungkeun Lee committed
	
    public DBServiceImpl() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
	Class.forName("com.mysql.jdbc.Driver").newInstance();
    }
Seungkeun Lee's avatar
Seungkeun Lee committed

    public DBServiceImpl( String driver, String prefix ) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
	Class.forName(driver).newInstance();
	driverPrefix = prefix;
    }
Seungkeun Lee's avatar
Seungkeun Lee committed

Seungkeun Lee's avatar
Seungkeun Lee committed
    public void init() {
    }
Seungkeun Lee's avatar
Seungkeun Lee committed
	 	
    public void connect( String password ) throws SQLException {
	connect( IPAddress, port, user, password );
    }
    
    public void connect( String user, String password ) throws SQLException {
	connect( IPAddress, port, user, password );
    }
    
    public void connect( String port, String user, String password ) throws SQLException {
	connect( IPAddress, port, user, password );
    }
    
    public void connect(String IPAddress, String port, String user, String password ) throws SQLException {
	connect( IPAddress, port, user, password, database );
	}

    public void connect(String IPAddress, String port, String user, String password, String database ) throws SQLException {
Jérôme Euzenat's avatar
Jérôme Euzenat committed
	conn = DriverManager.getConnection(driverPrefix+"://"+IPAddress+":"+port+"/"+database, user, password);
	st = (Statement) conn.createStatement();
Seungkeun Lee's avatar
Seungkeun Lee committed
	}
Seungkeun Lee's avatar
Seungkeun Lee committed

    public Connection getConnection() {
	return conn;
    }
Seungkeun Lee's avatar
Seungkeun Lee committed
	
    // JE: I think that there is no interest now
Seungkeun Lee's avatar
Seungkeun Lee committed
/*  public synchronized long nextID(){
	long id = 0;
	try {
	    st.executeUpdate("insert into id_seq (aa) values ('a')");
	    rs = (ResultSet) st.executeQuery("select max(id) from id_seq");
	    //System.err.println(rs.toString());
	    while(rs.next()) {
		id = rs.getInt(1);
	    }
	    //id = rs.getBigDecimal(1).longValue();
	} catch(Exception ex){
Seungkeun Lee's avatar
Seungkeun Lee committed
	}
Seungkeun Lee's avatar
Seungkeun Lee committed
    } */
Seungkeun Lee's avatar
Seungkeun Lee committed
	
    public void close() {
	try {
	    conn.close();
	    st.close();
	} catch (Exception ex) {
Jérôme Euzenat's avatar
Jérôme Euzenat committed
	    ex.printStackTrace();
Seungkeun Lee's avatar
Seungkeun Lee committed
	}
Seungkeun Lee's avatar
Seungkeun Lee committed
    
Seungkeun Lee's avatar
Seungkeun Lee committed
}