a09a80c36faa001d1a45a5aecb698fca

来自「超好用的企业员工信息管理系统」· 代码 · 共 64 行

TXT
64
字号
package com;

import java.sql.*;

public class DAO {
	private static Connection conn = null;
	private static String driver = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:oracle:thin:@localhost:1521:NEUSOFT";
	private static String user = "SCOTT";
	private static String pwd = "TIGER";
	private static Statement stmt = null;
	private static ResultSet rs = null;
	
	public static Connection getConnection(){
		try{
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url,user,pwd);
			if(conn!=null){
				System.out.println("连接Oracle数据库成功!");
			}
		}catch(Exception ex){
			System.out.println(ex.getMessage());
		}
		return conn;
	}
	
	public static ResultSet getEmployee(){
		conn = DAO.getConnection();
		try{
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select * from t_hong_userinfo");
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			
		}
		return rs;
	}
	public static void closeconn(){
		if(rs!=null){
			try{
				rs.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		if(stmt!=null){
			try{
				stmt.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try{
				conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?