亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我這里沒有顯示鼠標的懸??筛淖冺撁骖伾?,以為什么我加載了mysql的jar文件還是不能顯示報表的內容呢?

首先是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>原生態java環境生成報表</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="生成報表">

</form>

<table class="hovertable">

<tr>

<th colspan="5">利潤表</th>

</tr>

<tr>

<th>序號</th>

<th>商品名稱</th>

<th>賣出數量</th>

<th>交易筆數</th>

<th>盈利額</th>

</tr>

<%

List list = null;//初始化一個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.首先我們要初始化驅動包

? ?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();//單品利潤

? ??

? ? 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"));//這里獲得了賣出的數量

? ? }

? ? pf.setProfit(temp*pf.getTradingNumber());//總利潤=單品利潤*賣出的數量

? ? 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"));//這里獲得了賣出的數量

? ? }

? ? list.add(pf);//那我們取得的結果集pf(利潤)放到List集合里

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

? ? return list;

? ? }

}

https://img1.sycdn.imooc.com//5cd3a0c2000104d803990234.jpg

正在回答

1 回答

這樣直接看代碼看起來比較麻煩。。你需要把控制臺報的錯發出來。。

如果是數據庫沒連上,那你可以試一試在數據庫連接類里面寫一個main函數先試試自己的連接是否有問題。。當然按照視頻里這樣jar包,應該是沒有問題。。如果是你自己jar的包,還容易出現找不到jar包。

至于鼠標懸停,因為你連數據都沒有你怎么看它有沒有懸停變顏色。。你的表頭也就是th是沒有設置懸停樣式。。至于顯示的數據才有懸停樣式!!

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么我這里沒有顯示鼠標的懸??筛淖冺撁骖伾?,以為什么我加載了mysql的jar文件還是不能顯示報表的內容呢?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號