java1996
java1996
2017-12-02 01:04

哪个entity包为什么会报错,comm为什么也报错

  • comm
  • 数据库
  • entity

package Jlhy.DB;

import java.sql.*;
import java.util.*;
import entity.*;

public class CommentDao extends BaseDAO {
/**
* 获取所有留言
* */
public List GetComment(){
//SQL语句
String sql = "SELECT CID,CName,CContext FROM Comments";
List list = new ArrayList();
//数据库连接对象
Connection conn = null;
//SQL执行对象
PreparedStatement pstmt = null;
//数据库执行返回值
ResultSet rs = null;
try {
//创建数据库链接
conn = this.getConn();
//创建SQL执行对象
pstmt = conn.prepareStatement(sql);
//执行SQL语句 返回值
rs = pstmt.executeQuery();
//读取
while (rs.next()) {
comm comment = new comm();
comment.setCID(rs.getInt("CID"));
comment.setCName(rs.getString("CName"));
comment.setCContext(rs.getString("CContext"));
list.add(comment);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
//关闭
this.closeAll(conn, pstmt, rs);
}
return list;
}
public int AddComment(comm comment){
String sql = "INSERT INTO Comments VALUES(?,?)";
//受影响行数
int result = 0;

//数据库连接对象
Connection conn = null;
//SQL执行对象
PreparedStatement pstmt = null;
try {
//创建数据库链接
conn = this.getConn();
//创建SQL执行对象
pstmt = conn.prepareStatement(sql);
//设置参数
pstmt.setString(1, comment.getCName());
pstmt.setString(2, comment.getCContext());
//执行SQL语句
result = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally{
this.closeAll(conn, pstmt);
}
return result;
}
}图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答