public List getFwxxList(String title){
String sql="select * from fwxx where 1=1";
if(null!=title&&!title.trim().equals("")){
sql+="and title like '%"+title+"%' ";
}
sql+=" order by date desc";
//执行SQL返回结果
........这里应该怎么写,这个方法才算完整? }
private static Connection con = null;
private static PreparedStatement pst = null;
private static ResultSet rs = null;
public static int CheckUser(String username,String password)
{
int i = 0;
try
{
con = ConnectionDatabase.GetConnections();
pst = con.prepareStatement("sql语句");
rs = pst.executeQuery();
if(rs.next())
{
i = 10;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
pst.close();
con.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
return i;
}这是一个查询执行的代码,,,你这里应该将这个sql语句传到这个方法里面,,然后执行就可以啦。
private static PreparedStatement pst = null;
private static ResultSet rs = null;
public static int CheckUser(String username,String password)
{
int i = 0;
try
{
con = ConnectionDatabase.GetConnections();
pst = con.prepareStatement("sql语句");
rs = pst.executeQuery();
if(rs.next())
{
i = 10;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
pst.close();
con.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
return i;
}这是一个查询执行的代码,,,你这里应该将这个sql语句传到这个方法里面,,然后执行就可以啦。
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-12-16
返回List类型,你需要一个实体Bean 或者 用 Map 封装后返回也可以public List getFwxxList(String title){
String sql="select * from fwxx where 1=1";
if(null!=title&&!title.trim().equals("")){
sql+="and title like '%"+title+"%' ";
}
sql+=" order by date desc";
return this.getResult(sql);
} public List getResult(String sql){
List ls = new ArrayList();
Connection conn = null;
Statement st = null; //这里取得数据库连接,需自己改动
ResultSet rs = null;
try{
st = conn.createStatement();
rs = st.executeQuery(sql);
while(rs.next()){
FwxxBean fb = new FwxxBean(); //需要自己实现实体Bean,或者改成Map类型
fb.setXXX(rs.getString("字段名")); //设置查询的字段
ls.add(fb);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs != null)
rs.close();
if(st != null)
st.close();
if(conn != null){
conn.close();
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
return ls;
}本回答被网友采纳
String sql="select * from fwxx where 1=1";
if(null!=title&&!title.trim().equals("")){
sql+="and title like '%"+title+"%' ";
}
sql+=" order by date desc";
return this.getResult(sql);
} public List getResult(String sql){
List ls = new ArrayList();
Connection conn = null;
Statement st = null; //这里取得数据库连接,需自己改动
ResultSet rs = null;
try{
st = conn.createStatement();
rs = st.executeQuery(sql);
while(rs.next()){
FwxxBean fb = new FwxxBean(); //需要自己实现实体Bean,或者改成Map类型
fb.setXXX(rs.getString("字段名")); //设置查询的字段
ls.add(fb);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs != null)
rs.close();
if(st != null)
st.close();
if(conn != null){
conn.close();
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
return ls;
}本回答被网友采纳