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

📄 conn.java

📁 jsp版图书管理系统
💻 JAVA
字号:
package com.ww.j2ee;

import java.sql.*;
public class Conn{
	private static Connection con;
	private ResultSet rs;
	private Statement st;
	private static final String drivername="com.mysql.jdbc.Driver";
	private static final String url="jdbc:mysql://localhost:3306/j2ee_booksys?useUnicode=true&characterEncoding=GB2312";
	private static final String user="root";
	private static final String password="root";
	
	public static synchronized Connection getCon() throws Exception{
		try{
			Class.forName(drivername);
			con=DriverManager.getConnection(url,user,password);
			return con;
		}catch(Exception e){
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	public Statement getSt(){
		try{
			con=getCon();
			st=con.createStatement();
		    return st;	
		}catch(Exception e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
		return null;
	}
	
	public ResultSet getRs(String sql){
		try{
			st=getSt();
			rs=st.executeQuery(sql);
		    return rs;	
		}catch(Exception e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
		return null;
	}
	
	public synchronized void close(){
		try{
			if(st!=null){
				st.close();
				st=null;
			}
		}catch(Exception e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
		
		try{
			if(con!=null){
				con.close();
				con=null;
			}
		}catch(Exception e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
	}
	
	
}

⌨️ 快捷键说明

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