📄 notodaoimpl.java
字号:
package myitem.dao.impl;
import myitem.dao.NotoDAO;
import myitem.vo.Noto;
import myitem.db.*;
import java.util.*;
import java.sql.*;
public class NotoDAOImpl implements NotoDAO{
public void insert(Noto noto) throws Exception
{
String sql="insert into leaveword(name,tel,email,content,sj) values(?,?,?,?,?)";
PreparedStatement pstmt=null;
ConnectionDatabase dbc=null;
try
{
pstmt=dbc.getConn().prepareStatement(sql);
pstmt.setString(1,noto.getName());
pstmt.setString(2,noto.getTel());
pstmt.setString(3,noto.getEmail());
pstmt.setString(4,noto.getContent());
pstmt.setDate(5,new java.sql.Date(System.currentTimeMillis()));
pstmt.executeUpdate();
pstmt.close();
}
catch(Exception e)
{
throw new Exception("数据库操作出错");
}
finally{
try{
if(dbc != null)
{
dbc.close();
}
}
catch(Exception e)
{
}
}
}
public List queryAll() throws Exception
{
List all=new ArrayList();
String sql="select id,name,tel,email,content,hf,sj from leaveword order by sj desc";
PreparedStatement pstmt=null;
ConnectionDatabase dbc=null;
dbc = new ConnectionDatabase() ;
try
{
pstmt=dbc.getConn().prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while(rs.next())
{
Noto noto=new Noto();
noto.setId(rs.getInt(1));
noto.setName(rs.getString(2));
noto.setTel(rs.getString(3));
noto.setEmail(rs.getString(4));
noto.setContent(rs.getString(5));
noto.setHf(rs.getString(6));
noto.setSj(rs.getString(7));
all.add(noto);
}
rs.close();
pstmt.close();
}
catch(Exception e)
{
System.out.println(e) ;
throw new Exception("操作中出现错误!!!") ;
}
finally{
try{
if(dbc != null)
{
dbc.close();
}
}
catch(Exception e)
{
}
}
return all;
}
public void delword(int id) throws Exception
{
String sql="delete from leaveword where id=?";
PreparedStatement pstmt=null;
ConnectionDatabase dbc=null;
dbc = new ConnectionDatabase();
try
{
pstmt=dbc.getConn().prepareStatement(sql);
pstmt.setInt(1, id);
pstmt.executeUpdate();
pstmt.close();
}
catch(Exception e)
{
}
finally
{
try
{
if(dbc!=null)
{
dbc.close();
}
}
catch(Exception e)
{
}
}
}
public Noto queyid(int id) throws Exception
{
String sql="select name,content,id,hf from leaveword where id=?";
PreparedStatement pstmt=null;
ConnectionDatabase dbc=null;
dbc = new ConnectionDatabase();
Noto noto=new Noto();
try
{
pstmt=dbc.getConn().prepareStatement(sql);
pstmt.setInt(1, id);
ResultSet rs=pstmt.executeQuery();
if(rs.next())
{
noto.setName(rs.getString(1));
noto.setContent(rs.getString(2));
noto.setId(rs.getInt(3));
noto.setHf(rs.getString(4));
}
rs.close();
pstmt.close();
}
catch(Exception e)
{
}
finally
{
try
{
if(dbc!=null)
{
dbc.close();
}
}
catch(Exception e)
{
}
}
return noto;
}
public void inserthf(Noto note) throws Exception
{
String sql="update leaveword set hf=? where id=?";
PreparedStatement pstmt=null;
ConnectionDatabase dbc=null;
dbc = new ConnectionDatabase();
try
{
pstmt=dbc.getConn().prepareStatement(sql);
pstmt.setString(1, note.getHf());
pstmt.setInt(2, note.getId());
pstmt.executeUpdate();
pstmt.close();
}
catch(Exception e)
{
System.out.print("数据库操作出错");
}
finally
{
try
{
if(dbc!=null)
{
dbc.close();
}
}
catch(Exception e)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -