/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kr.org.kisti.morph;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hwang
*/
public class DBConnection {
public DBConnection() {
dbconn = null;
stmt = null;
rs = null;
dburl = "jdbc:oracle:thin:@localhost:1521:XE";
dbuser = "hr";
dbpass = "";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(Exception exception)
{
System.out.println(exception);
}
try
{
dbconn = DriverManager.getConnection(dburl, dbuser, dbpass);
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception);
}
}
public Connection getConnection() {
return dbconn;
}
public List<String> ExcuteQuery(String query) {
List<String> result = new ArrayList<String>(); //Size problem
try {
stmt = dbconn.createStatement();
rs = stmt.executeQuery(query);
while (rs.next()) {
result.add(rs.getString("paper_nm"));
}
rs.close();
stmt.close();
} catch (SQLException e) {
System.out.println(e);
}
return result;
}
public void close(){
if(dbconn != null) {
try {
dbconn.close();
} catch (SQLException e) {
System.out.println(e);
}
}
}
Connection dbconn;
Statement stmt;
ResultSet rs;
String dburl;
String dbuser;
String dbpass;
}
'백엔드기술 > 개발언어' 카테고리의 다른 글
한자를 한글로 변환하기 (4) | 2010.07.22 |
---|---|
임시 참조 - 루씬 한글 형태소 분석기 사용하기 (Util) (0) | 2010.05.25 |
임시 참조 - 루씬 한글형태소분석기 사용하기(main) (0) | 2010.05.25 |