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();


}

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

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭