import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnector
{
private static final String JDBC_DRIVER = "JDBC 드라이버";
private static final String JDBC_URL = "DB RUL";
private static final String JDBC_USERNAME = "사용자 아이디";
private static final String JDBC_PASSWORD = "비밀번호";
private Connection connection = null ;
private Statement statement = null ;
/**
*
* @throws ClassNotFoundException
* @throws SQLException
*/
public DBConnector() throws ClassNotFoundException, SQLException {
this(JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD);
}
/**
*
* @param driver TODO
* @param url
* @param user
* @param pass
* @throws ClassNotFoundException
* @throws SQLException
*/
public DBConnector(String driver, final String url, final String user, final String pass) throws ClassNotFoundException, SQLException {
Class.forName(driver);
setConfiguration(url, user, pass);
}
/**
*
* @param jdbcDriver TODO
* @param url
* @param user
* @param pass
* @throws SQLException
*/
public final void setConnection(String jdbcDriver, final String url, final String user, final String pass) throws ClassNotFoundException, SQLException {
Class.forName(jdbcDriver);
setConfiguration(url, user, pass);
}
/**
*
* @param url
* @param user
* @param pass
* @throws SQLException
*/
private final void setConfiguration(final String url, final String user, final String pass) throws SQLException {
connection = DriverManager.getConnection(url, user, pass);
statement = connection.createStatement();
}
/**
*
* @param sql
* @return
* @throws SQLException
*/
public final ResultSet executeQuery(String sql) throws SQLException {
return statement.executeQuery(sql);
}
/**
*
* @param sql
* @return
* @throws SQLException
*/
public final int executeUpdate(String sql) throws SQLException {
return statement.executeUpdate(sql);
}
/**
* 커넥션 객체를 close 시킨다.
* @throws SQLException
*/
public final void DBConnectClose() throws SQLException
{
connection.close();
}
}
'IT_Programming > Java' 카테고리의 다른 글
JTable setPreferredWidth 각 컬럼 너비조절 (0) | 2008.08.20 |
---|---|
JTabbedPane 에서 탭 스타일 수정하기 (0) | 2008.08.20 |
[펌] 자바 가상 머신이란? (0) | 2008.07.27 |
[펌] MIDI SOUND 생성하기 ▷ J2SE (0) | 2008.07.23 |
Eclipse SWT Event 정리 (0) | 2008.06.27 |