java代码087

code087.java

package pack02;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class code087
{
    public Connection getConnection()
    {
        Connection conn = null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/test";
            String user = "root";
            String pwd = "mysql123";
            conn = DriverManager.getConnection(url,user,pwd);

        } 
        catch (ClassNotFoundException e) 
        {
            e.printStackTrace();
        } 
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        return conn;
    }

    public List<code086> findAll()
    {
        List<code086> list1 = new ArrayList<code086>();
        Connection conn = this.getConnection();
        try
        {
            String procedure = "{call findAllBook()}";
            CallableStatement statement = conn.prepareCall(procedure);
            ResultSet rSet = statement.executeQuery();

            while (rSet.next())
            {
                code086 book = new code086();
                book.setId(rSet.getInt("id"));
                book.setName(rSet.getString("name"));
                book.setPrice(rSet.getDouble("price"));
                book.setBookCount(rSet.getInt("bookCount"));
                book.setAuthor(rSet.getString("author"));
                list1.add(book);
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return list1;
    }
}

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0