為什么我這里沒(méi)有顯示鼠標(biāo)的懸??筛淖冺?yè)面顏色,以為什么我加載了mysql的jar文件還是不能顯示報(bào)表的內(nèi)容呢?
首先是index.jsp
<%@ page language="java" import="java.util.*,beans.*"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<title>原生態(tài)java環(huán)境生成報(bào)表</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!-- CSS -->
<style type="text/css">
table.hovertable {
font-family: verdana, arial, sans-serif;
font-size: 13px;
color: #333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table.hovertable th {
background-color: #c3dde0;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.hovertable tr {
background-color: #d4e3e5;
}
table.hovertable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
</style>
</head>
<body>
<form action="ShowReport" method="post">
<input type="submit" value="生成報(bào)表">
</form>
<table class="hovertable">
<tr>
<th colspan="5">利潤(rùn)表</th>
</tr>
<tr>
<th>序號(hào)</th>
<th>商品名稱</th>
<th>賣出數(shù)量</th>
<th>交易筆數(shù)</th>
<th>盈利額</th>
</tr>
<%
List list = null;//初始化一個(gè)List
if (session.getAttribute("PROFIT") != null) {
list = (List) session.getAttribute("PROFIT");
if (list.size() > 0) {
int temp = 0;
int temp1 = 0;
int temp2 = 0;
int temp3 = 0;
Profit pf;
for (int i = 0; i < list.size(); i++) {
pf = new Profit();
pf = (Profit) list.get(i);
%>
<tr onmouseover="this.style.backgroundColor='#ffff66';"
onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><%=temp+=1%></td>
<td><%=pf.getGoodsName()%></td>
<td><%=pf.getTradingNumber()%></td>
<td><%=pf.getTimes()%></td>
<td><%=pf.getProfit()%></td>
</tr>
<%
}
}
}
%>
</table>
</body>
</html>
然后是我的JdbcConn類
public class JdbcConn {
? ?private static String url="jdbc:mysql://127.0.0.1:3306/TestReport";
? ?private static String user = "root";
? ?private static String password = "123";
? ?public static Connection conn;
? ?public static PreparedStatement ps;
? ?public static ResultSet rs;
? ?public static Statement st;
? ?
? ?public static Connection getConnection(){
? ?//1.首先我們要初始化驅(qū)動(dòng)包
? ?try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,user,password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
? ?return conn;
? ?}
}
這是我的Service類
public class Service {
private Connection dbConnection;
? ? private Statement st,st1,st2;
? ? private ResultSet rs,rs1,rs2;
? ? private String sql;
? ? private List list;
? ? private Profit pf;
? ??
? ? public List getProfit(){
? ? list = new ArrayList();
? ? dbConnection = JdbcConn.getConnection();
? ? try {
st = (Statement)dbConnection.createStatement();
st1 = (Statement)dbConnection.createStatement();
st2 = (Statement)dbConnection.createStatement();
sql="select g.goods_name goodsName,g.selling_price selling,g.cost_price costPrice,g.goods_id goodsId"
+ "from goods g,trading t"
+ "where t.trading_goods_id=g.goods_id"
+ "group by g.goods_name;";
rs = st.executeQuery(sql);
int temp;
while(rs.next()){
pf = new Profit();
pf.setGoodsName(rs.getString("goodsName"));
pf.setSellingPrice(rs.getInt("selling"));
pf.setCostPrice(rs.getInt("selling"));
pf.setGoodsId(rs.getInt("goodsId"));
temp=0;
? ? temp=pf.getSellingPrice()-pf.getCostPrice();//單品利潤(rùn)
? ??
? ? sql="select sum(t.trading_number) sumNum from trading t where t.trading_goods_id= "+pf.getGoodsId();
? ? rs1=st1.executeQuery(sql);
? ? while(rs1.next()){
? ? pf.setTradingNumber(rs1.getInt("sumNum"));//這里獲得了賣出的數(shù)量
? ? }
? ? pf.setProfit(temp*pf.getTradingNumber());//總利潤(rùn)=單品利潤(rùn)*賣出的數(shù)量
? ? sql="select count(t.trading_id) times from trading t where t.trading_goods_id= "+pf.getGoodsId();
? ? rs2=st2.executeQuery(sql);
? ? while(rs2.next()){
? ? pf.setTradingNumber(rs1.getInt("times"));//這里獲得了賣出的數(shù)量
? ? }
? ? list.add(pf);//那我們?nèi)〉玫慕Y(jié)果集pf(利潤(rùn))放到List集合里
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
? ? return list;
? ? }
}
2019-07-05
這樣直接看代碼看起來(lái)比較麻煩。。你需要把控制臺(tái)報(bào)的錯(cuò)發(fā)出來(lái)。。
如果是數(shù)據(jù)庫(kù)沒(méi)連上,那你可以試一試在數(shù)據(jù)庫(kù)連接類里面寫一個(gè)main函數(shù)先試試自己的連接是否有問(wèn)題。。當(dāng)然按照視頻里這樣jar包,應(yīng)該是沒(méi)有問(wèn)題。。如果是你自己jar的包,還容易出現(xiàn)找不到j(luò)ar包。
至于鼠標(biāo)懸停,因?yàn)槟氵B數(shù)據(jù)都沒(méi)有你怎么看它有沒(méi)有懸停變顏色。。你的表頭也就是th是沒(méi)有設(shè)置懸停樣式。。至于顯示的數(shù)據(jù)才有懸停樣式?。?br />