(1)使用JDBC数据库连接技术,编写JDBCUtil工具类,在该类中定义getCon方法用于获得与数据库的连接对象,定义closeAll方法用于释放连接对象等资源。import java.sql.*;public class JDBCUtil {private static String user="用户名";private static String password="密码";private static String url="jdbc:mysql://localhost:3306/数据库名"; private static String driver="com.mysql.jdbc.Driver"; public static Connection getCon() { try { return DriverManager.getConnection(url, user, password); } catch (SQLException e) { throw new RuntimeException(e); } } public static void closeAll(ResultSet set, PreparedStatement statement, Connection connection) { try { if (set != null) { set.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(e); } }}(2)应用类的封装性,创建book表对应的类,其中book表存储图书id(主键、自增)、书名、价格、作者、库存量等信息。public class Book { private Integer id; private String name; private Double price; private String author; private Integer reserve; public Book() { } public Book(Integer id, String name, Double price, String author, Integer reserve) { this.id = id; this.name = name; this.price = price; this.author = author; this.reserve = reserve; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public Integer getReserve() { return reserve; } public void setReserve(Integer reserve) { this.reserve = reserve; } @Override public String toString() { return "Book{" + "id=" + id + ", name='" + name + ''' + ", price=" + price + ", author='" + author + ''' + ", reserve=" + reserve + '}'; }}(3)创建BookDao类,完成增加图书信息的方法,并编写Test测试类测试。import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException; public class BookDao { static Connection con = null; static ResultSet set=null; static PreparedStatement ps=null; public static void addBook(String name,double price,String author,int reserve) { String sql="insert into book values(null,?,?,?,?);"; try { con=JDBCUtil.getCon(); ps=con.prepareStatement(sql); ps.setString(1,name); ps.setDouble(2,price); ps.setString(3,author); ps.setInt(4,reserve); ps.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }finally { JDBCUtil.closeAll(null,ps,con); } } public static void select(){ String sql="select *from book"; con=JDBCUtil.getCon(); try { ps=con.prepareStatement(sql); set= ps.executeQuery(); while (set.next()){ System.out.println("Book{" + "id=" + set.getInt("id") + ", name='" + set.getString("name") + ''' + ", price=" + set.getDouble("price") + ", author='" + set.getString("author") + ''' + ", reserve=" + set.getInt("reserve") + '}'); } } catch (SQLException e) { e.printStackTrace(); }finally { JDBCUtil.closeAll(set,ps,con); } }}TESTpublic class Test { public static void main(String[] args) { BookDao.addBook("老人与海",32.1,"海明威",4); BookDao.select(); }}使用循环和break、continue等流程控制语句,计算1-n全部偶数的和,n的值在控制台输入。import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int sum = 0; for (int index = 1; index < n; index++) { if (index % 2 != 0) { continue; } sum += index; } System.out.println(sum); }}一张纸的厚度大约是0.08mm,对折多少次之后能达到或超过珠穆朗玛峰的高度(8848.13米)。public class Main { public static void main(String[] args) { //为了便于计算将原值扩大100倍 long start=8; //1mm=0.001m long end=884813000; long count=0; while (start



