btypedb.java

来自「《Web程序测试实训教程(Java版)》-徐民鹰-源代码」· Java 代码 · 共 58 行

JAVA
58
字号
package bookType;

import java.sql.*;
import java.util.*;
import com.ConnDB1;

public class BtypeDB extends ConnDB1 implements IBtypeDB{
	//Connection connection;
    private ArrayList booktype;
   
    public BtypeDB ()throws Exception
    {
        //
    }

    //
     
    public Btype getType (int id)
    {
        try
        {
        	ConnDB1.initialize();	// create database connection
            PreparedStatement preparedStatement = aConnection.prepareStatement ("SELECT bookTypeId, bookType FROM bookType WHERE bookTypeId = ?");
            preparedStatement.setInt (1, id);
            ResultSet resultSet = preparedStatement.executeQuery ();
            if (resultSet.next ())
            {
            	Btype btypes = new Btype
                (
                    resultSet.getInt (1), resultSet.getString (2)
                );
                preparedStatement.close ();
                ConnDB1.terminate();
                return btypes;
            }
            else
            {
                preparedStatement.close ();
                ConnDB1.terminate();
                return null;
            }
        }
        catch (SQLException e)
        {
        	ConnDB1.terminate();
            return null;
        }
    }

    public int addType (Btype btypes)
    {
        int rowsAffected = 0;
        try
        {
        	ConnDB1.initialize();	// create database connection
            PreparedStatement preparedStatement = aConnection.prepareStatement ("INSERT INTO bookType (bookType) VALUES (?)");
            preparedStatement.setString (1, btypes.getType());
            //鍒ゆ柇鏄

⌨️ 快捷键说明

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