为何我dbutil里定义了getpj方法 还是报么有定义方法的错?
问题描述:
<%@ page
contentType="text/html;charset=utf-8"
import="com.bn.shop.DBUtil,java.util.*"
%>
<html>
<head>
<title>所有评价</title>
<link rel="shortcut icon" href="jqm145/demos/favicon.ico">
<link rel="stylesheet" href="jqm145/demos/css/themes/default/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" href="jqm145/demos/_assets/css/jqm-demos.css">
<script src="jqm145/demos/js/jquery.js"></script>
<script src="jqm145/demos/_assets/js/index.js"></script>
<script src="jqm145/demos/js/jquery.mobile-1.4.5.min.js"></script>
<style type="text/css"></style>
<link rel="stylesheet" href="css/styles.css" type="text/css">
</head>
<script>
function showLoader() {//显示加载器
$.mobile.loading('show', {
text: '加载中...', //加载器中显示的文字
textVisible: true, //是否显示文字
theme: 'a', //加载器主题样式a-e
textonly: false, //是否只显示文字
html: "" //要显示的html内容,如图片等
});
}
function hideLoader()//隐藏加载器
{
$.mobile.loading('hide');
}
</script>
<body>
<%
String id=request.getParameter("id");
List<String[]> ls=new ArrayList<String[]>();
String[][] pjMess=null;//user_pic,user_name,pj_date,pj_content
ls=DBUtil.getYlPj(id);
pjMess=new String[ls.size()][ls.get(0).length];
for(int i=0;i<ls.size();i++){
for(int j=0;j<ls.get(0).length;j++){
pjMess[i][j]=ls.get(i)[j];
System.out.println(pjMess[i][1]);
}
}
%>
<div data-role="page" data-theme="a">
<div data-role="header" class="title">
<div >所有评价<br></div>
</div>
<%
for(int i=0;i<pjMess.length;i++){
%>
<ul data-role="listview" style=" background:#fff">
<li>
<img src="img/<%=pjMess[i][0]%>">
<table>
<tr><td> <p> <%=pjMess[i][1]%></p> </td></tr>
<tr><td> <p> <%=pjMess[i][2].substring(0,16)%></p> </td></tr>
</table>
</li>
<div style="text-indent: 2em; background:#fff" >
<p ><%=pjMess[i][3]%><br><br></p>
</div>
</ul>
<%
}
%>
</div>
</body>
</html>
package com.bn.shop;
import java.sql.*;
import java.util.*;
import com.mchange.v2.c3p0.*;
public class DBUtil
{
static ComboPooledDataSource dataSource;
static
{
//连接池数据源
dataSource=new ComboPooledDataSource();
//数据用户名
dataSource.setUser("root");
//数据库密码
dataSource.setPassword("");
//数据库连接URL
dataSource.setJdbcUrl("jdbc:mysql://localhost/zol?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false");
//数据库连接驱动,注意:必须在项目中导入对应数据库的驱动jar包
try{dataSource.setDriverClass("org.gjt.mm.mysql.Driver"); }catch(Exception e){e.printStackTrace();}
//初始化大小
dataSource.setInitialPoolSize(5);
//最小池大小
dataSource.setMinPoolSize(1);
//最大池大小
dataSource.setMaxPoolSize(10);
dataSource.setMaxStatements(50);
dataSource.setMaxIdleTime(60);
}
public static Connection getConnection() throws Exception
{
return dataSource.getConnection();
}
//获取全部评价
public static List<String[]> getPj(String id)
{
List<String[]> lstr=new ArrayList<String[]>();
Connection con=null;
Statement st=null;
ResultSet rs=null;
try{
con=getConnection();
st=con.createStatement();
String sql="select user.user_pic,user.user_name,commoditycomment.CommodityCommentDate,commoditycomment.CommodityCommentContent,commoditycomment.Delete02 from commoditycomment,user where commoditycomment.UserId=user.user_id and commoditycomment.CommodityNumber='"+id+"' ;";
rs=st.executeQuery(sql);
while(rs.next())
{
String [] str=new String [5];
str[0]=rs.getString(1);
str[1]=rs.getString(2);
str[2]=rs.getString(3);
str[3]=rs.getString(4);
str[4]=rs.getString(5);
lstr.add(str);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{rs.close();}catch(Exception e){e.printStackTrace();}
try{st.close();}catch(Exception e){e.printStackTrace();}
try{con.close();}catch(Exception e){e.printStackTrace();}
}
return lstr;
}
}
答
先把DBUtil单独编译下看看有没有出错。