public classtest {
DBConn dbconn=newDBConn();
Connection con=dbconn.getConn();
PreparedStatement pstmt=null;
ResultSet rs=null;/*** search查找*/
public voidgetAll(){
String sql="select * from TEST..lyTable";try{
pstmt=con.prepareStatement(sql);
rs=pstmt.executeQuery();while(rs.next()){
LyTable ly=newLyTable();
ly.setId(rs.getInt(1));
ly.setUserId(rs.getInt(2));
ly.setDate(rs.getDate(3));
ly.setTitle(rs.getString(4));
ly.setContent(rs.getString(5));
System.out.println(ly.toString());
}
}catch(SQLException e) {
e.printStackTrace();
}
}/*** insert插入
*@paramly*/
private voidinsert(LyTable ly) {
String sql= "insert into Test..lyTable values(?,?,?,?)";try{
pstmt=con.prepareStatement(sql);
pstmt.setInt(1, ly.getUserId());
pstmt.setDate(2, ly.getDate());
pstmt.setString(3,ly.getTitle());
pstmt.setString(4,ly.getContent());
pstmt.executeUpdate();
}catch(SQLException e) {
e.printStackTrace();
}
}/*** delete删除
*@paramid*/
private voiddelete(Integer id) {
String sql= "delete from TEST..lyTable where id=?";try{
pstmt=con.prepareStatement(sql);
pstmt.setInt(1, id);
pstmt.executeUpdate();
}catch(SQLException e) {
e.printStackTrace();
}
}/*** update 修改
*@paramly*/
private voidupdate(LyTable ly) {
String sql= "update TEST..lyTable set content='"+ly.getContent()+"' where title='"+ly.getTitle()+"'";try{
pstmt=con.prepareStatement(sql);
pstmt.executeUpdate();
}catch(SQLException e) {
e.printStackTrace();
}
}}