JDBC는 EXCEL 데이터를 데이터베이스에 저장합니다(1.JDBC 운영 체제)

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *  JDBC  
 *   ( )
 *   sqlserver
 */
public final class JDBCUtilSingle {
	static String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	static String url = "jdbc:sqlserver://ip:port;DatabaseName=test";
	static String username = "sa";
	static String password = "sa";
	static Connection conn = null;
	private static JDBCUtilSingle instance = null;
	
	private JDBCUtilSingle() {
	}
	
	/**
	 *  JDBCUtilSingle 
	 * @return
	 */
	public static JDBCUtilSingle getInstance(){
		if(instance == null){
			synchronized(JDBCUtilSingle.class){ //    
				if(instance == null){
					instance = new JDBCUtilSingle();
				}
			}
		}
		return instance;
	}

	/**
	 *  , 
	 */
	static{
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	/**
	 *  
	 * @return
	 */
	public Connection getConnection(){
		try {
			conn = DriverManager.getConnection(url,username,password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	/**
	 *  
	 * @param rs
	 * @param st
	 * @param conn
	 */
	public void closeConnection(ResultSet rs, Statement st, Connection conn){
		try {
			if(rs != null){
				rs.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try{
				if(st != null){
					st.close();
				}
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				try{
					if(conn != null){
						conn.close();
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
	}

}

좋은 웹페이지 즐겨찾기