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

📄 wearnesdb.java

📁 provide a room booking system
💻 JAVA
字号:
package Wearnes;
import java.sql.*; 
import java.util.*; 

public class WearnesDB
{ 

	 Connection conn = null; 
	Statement stmt = null; 
	ResultSet rs = null; 
	//String url; 
	String url="jdbc:mysql://localhost:3306/wearnes?user=guo&password=password"; 
        private static WearnesDB wearnesDB;
	/*public static void main (String args[]) */ 
        public static WearnesDB getInstance(String u)
        {
            if(wearnesDB==null)
            {
             wearnesDB=new  WearnesDB(u);
            }
            return wearnesDB;
        }
	public WearnesDB(String u) 
	{ 
            
            url=u;          
            try { 
            Class.forName ("com.mysql.jdbc.Driver"); 
            conn = DriverManager.getConnection(url); 
            } 
            catch (Exception e) { 
            System.err.println("elib():"+e.getMessage()); 
            } 
	} 
        public WearnesDB() 
	{ 
           
            try { 
            Class.forName ("com.mysql.jdbc.Driver"); 
            } 
            catch (java.lang.ClassNotFoundException e) { 
            System.err.println("elib():"+e.getMessage()); 
            } 
	} 
	public ResultSet select(String sql) throws SQLException 
	{ 
	
	stmt = conn.createStatement(); 
	rs = stmt.executeQuery(sql); 
	return rs; 
	} 
	
	public boolean update(String sql) throws SQLException 
	{ 
	try 
	{ 
	stmt = conn.createStatement(); 
	stmt.executeUpdate(sql); 
	} 
	catch(SQLException ex) 
	{ 
	System.err.println(ex.getMessage()); 
	return false; 
	} 
	finally 
	{ 
	return true; 
	} 
	} 
	
	public boolean insert(String sql) throws SQLException 
	{ 
            try 
            { 
           // conn = DriverManager.getConnection(url); 
            stmt = conn.createStatement(); 
            stmt.executeUpdate(sql); 
            } 
            catch(SQLException ex) 
            { 
            System.err.println(ex.getMessage()); 
            return false; 
            } 
            finally 
            { 
            return true; 
            } 
	} 
	
	
	public boolean create(String sql) throws SQLException 
	{ 
	try 
	{ 
	//conn = DriverManager.getConnection(url); 
	stmt = conn.createStatement(); 
	stmt.executeUpdate(sql); 
	} 
	catch(SQLException ex) 
	{ 
	System.err.println(ex.getMessage()); 
	return false; 
	} 
	finally 
	{ 
	return true; 
	} 
	} 
	
	
	
	public boolean mdelete(String sql) throws SQLException 
	{ 
	try 
	{ 
//	conn = DriverManager.getConnection(url); 
	stmt = conn.createStatement(); 
	stmt.executeUpdate(sql); 
	} 
	catch(SQLException ex) 
	{ 
	System.err.println(ex.getMessage()); 
	return false; 
	} 
	finally 
	{ 
	return true; 
	} 
	} 
	
	public boolean closeConn() 
	{ 
	try { 
	if(rs!=null) rs.close(); 
	if(stmt!=null) stmt.close(); 
	if(conn!=null) conn.close(); 
	return true; } 
	catch (SQLException e) { 
	System.err.println("closeConn:"+e.getMessage()); 
	return false; } 
	} 
	public static void main(String args[])
	{
		
	}
} 

⌨️ 快捷键说明

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