/* * To change this template, choose Tools | Templates * and open the template in the editor. */package book_booking;import java.sql.*;/** * * @author Administrator */public class SqlBean { private Connection conn=null;private ResultSet rs=null; //Database driverprivate String DatabaseDriver="sun.jdbc.odbc.JdbcOdbcDriver"; //Database sourse private String DatabaseConnStr="jdbc:odbc:star"; //ID to loginprivate String LogId="wsw"; //Password to loginprivate String LogPass="232425"; //Constructor methodpublic SqlBean(){try{Class.forName(DatabaseDriver);}catch(ClassNotFoundException ex){ System.err.println(ex);}} //selectpublic ResultSet executeQuery(String sql){rs=null;try{conn = DriverManager.getConnection(DatabaseConnStr,LogId,LogPass);Statement stmt=conn.createStatement();rs=stmt.executeQuery(sql);}catch(SQLException ex){ System.err.println(ex);}return rs;} //insertpublic int executeInsert(String sql){int num=0;try{conn = DriverManager.getConnection(DatabaseConnStr,LogId,LogPass);Statement stmt=conn.createStatement();num=stmt.executeUpdate(sql);}catch(SQLException ex){ System.err.println(ex);}return num;} //deletepublic int executeDelete(String sql){int num=0;try{conn = DriverManager.getConnection(DatabaseConnStr,LogId,LogPass);Statement stmt=conn.createStatement();num=stmt.executeUpdate(sql);}catch(SQLException ex){ System.err.println(ex);}return num;} //updatepublic int executeUpdate(String sql){int num=0;try{conn = DriverManager.getConnection(DatabaseConnStr,LogId,LogPass);Statement stmt=conn.createStatement();num=stmt.executeUpdate(sql);}catch(SQLException ex){ System.err.println(ex);}return num;} //closepublic void CloseDataBase(){try{conn.close();}catch(Exception ex){ System.err.println(ex);}}}