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

📄 buku.java

📁 this is a java source code file.. download and enjoy of it...
💻 JAVA
字号:
/*
 * Buku.java
 *
 * Created on April 12, 2007, 1:25 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package inc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author mamat-dev
 */
public class Buku {

   private String query;
    
    /** Creates a new instance of Buku */
    public Buku() {
    }
    
    public boolean insertBuku(String title, String pengarang, String statusId) {
        boolean status = false;
        MsAcces buku = new MsAcces();
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            st.executeUpdate("insert into book (book_title,book_author,book_status_id) values('"+title+"','"+pengarang+"',"+statusId+")");
            buku.closeStatement();
            buku.closeConnection();            
            status = true;
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return status;
    }
    
    public boolean deleteBuku(String book_id){
        boolean status = false;
        MsAcces buku = new MsAcces();
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            st.executeUpdate("delete from book where book_id = "+book_id+"");
            buku.closeStatement();
            buku.closeConnection();
            status = true;
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return status;
    }
    
    public boolean updateBuku(String book_id, String book_title, String book_author,
            String book_status){
        boolean status = false;
        MsAcces buku = new MsAcces();
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            st.executeUpdate("update book set book_title = '"+book_title
                    +"', book_author='"+book_author+"',book_status_id="+
                    book_status+" where book_id ="+book_id);
            buku.closeStatement();
            buku.closeConnection();
            status = true;
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return status;
    }
    
    public ResultSet selectBuku(String query){
        ResultSet rs = null;
        MsAcces buku = new MsAcces();
        
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            rs = st.executeQuery(query);
            
            return rs;
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return rs;
    }
    
    public int getRow(String query){
        MsAcces buku = new MsAcces();
        int row = 0;
        
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            ResultSet rs = st.executeQuery(query);         
            
            while(rs.next()){
                row++;
            }
            return row;
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return row;
    }
    
    public String getStatus(String statusId){
        String status =null;
        MsAcces buku = new MsAcces();
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            ResultSet rs = st.executeQuery("select book_description from book_status where book_status_id = "+statusId);
            while(rs.next()){
                return rs.getString(1);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return status;
    }
    
    public void updateStatusBuku(String bookId, String statusId){
        MsAcces buku = new MsAcces();
        try {
            buku.getConnection();
            Statement st = buku.getStatement();
            st.executeUpdate("update book set book_status_id ="+statusId+" where book_id="+bookId);
            buku.closeStatement();
            buku.closeConnection();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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