代码如下:
JSP:
<div class="container">
<table class="table table-striped table-hover">
<tr>
<th>编号</th>
<th>名字</th>
<th>价格</th>
<th>库存</th>
<th>生产日期</th>
<th>操作</th>
</tr>
<%
//定义集合 存储商品信息
ArrayList<Shops> list = new ArrayList<Shops>();
//通过JDBC把数据库值取给List
Class.forName("com.gzlg.bigdata.Database");
String name = "root";
String pwd = "123456";
String url = "jdbc:mysql://localhost:3306/wrok?useSSL=false&serverTimezone=UTC";
Connection connection = DriverManager.getConnection(url, name, pwd);
String sql = "SELECT * FROM shops;";
PreparedStatement pst = connection.prepareStatement(sql);
ResultSet res = pst.executeQuery();
while (res.next()) {
Shops shops1 = new Shops();
shops1.setShopid(res.getInt(1));
shops1.setShopName(res.getString(2));
shops1.setPrice(res.getFloat(3));
shops1.setCount(res.getInt(4));
shops1.setMakedate(res.getString(5));
list.add(shops1);
}
for (int i = 0; i < list.size(); i++) {
out.print(" <tr >\n" +
" <td >" + list.get(i).getShopid() + " </td >\n" +
" <td > " + list.get(i).getShopName() + " </td >\n" +
" <td > " + list.get(i).getPrice() + " </td >\n" +
" <td > " + list.get(i).getCount() + " </td >\n" +
" <td > " + list.get(i).getMakedate() + "</td >\n" +
" </tr >");
}
%>
</table>
</div>
然后通过Tomcat运行出来就报:
javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/wrok?useSSL=false&serverTimezone=UTC 这个错误。
已经将jar放Tomcat目录的lib下还是运行不了。