SQL笔记

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=DB";
String username = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, username,
password);
String sql = "select * from TB";
Statement statement = conn.createStatement();

ResultSet resultSet = statement.executeQuery(sql);


List<Book> list = new ArrayList<Book>();
while (resultSet.next()) {


Book book = new Book();
book.setId(resultSet.getInt("id"));
book.setName(resultSet.getString("name"));
book.setPrice(resultSet.getDouble("price"));
book.setBookCount(resultSet.getInt("bookCount"));
book.setAuthor(resultSet.getString("author"));
list.add(book);


}
request.setAttribute("list", list);
resultSet.close();
statement.close();
conn.close();


}
阅读更多
个人分类: SQL
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭