⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbc_util.java

📁 jdbc个人编写的通讯录
💻 JAVA
字号:
package com.sunny.address.util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
 
public class JDBC_Util {
	private static String driverClass="";
	private static String url="";
	private static String username="";
	private static String password="";
	static{
		InputStream input =JDBC_Util.class.getResourceAsStream("/jdbc_util.properties");
		Properties properties=new Properties();
		
		try{
			properties.load(input);
			driverClass=properties.getProperty("jdbc.driverClass");
			url=properties.getProperty("jdbc.url");
			username=properties.getProperty("jdbc.username");
			password=properties.getProperty("jdbc.password");
			
			Class.forName(driverClass);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static Connection getConnection(){
		Connection connection=null;
		try{
			connection=DriverManager.getConnection(url,username,password);
		}catch(Exception e){
			e.printStackTrace();
		}
		return connection;
		
	}
	private Connection connection=null;
	private Statement statement =null;
	private ResultSet resultSet =null;
	
	public void addRecord(String insert) throws SQLException{
		
		statement =connection.createStatement();
		statement.execute(insert);
		statement.close();
		
	}
	public void updateRecord(String update) throws SQLException{
		statement=connection.createStatement();
		statement.execute(update);
		statement.close();
	}
	public ResultSet search(String select) throws SQLException{
		statement=connection.createStatement();
		statement.execute(select);
		return resultSet;
	}
	
	public static void close(
			ResultSet resultSet,PreparedStatement preparedStatement,Connection connection){
		    if(resultSet!=null){
				try{
					resultSet.close();
				}catch(Exception e){
				   e.printStackTrace();
				}
			}
			 if(preparedStatement!=null){
				try{
					preparedStatement.close();
				}catch(Exception e){
				   e.printStackTrace();
				}
			}
			 if(connection!=null){
				try{
					connection.close();
				}catch(Exception e){
				   e.printStackTrace();
				}
			}
		}
}

⌨️ 快捷键说明

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