public int guahaoAdd(Connection con, GuaHao guahao)throws Exception{
String sql="insert into t_ghinfo values(null,?,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setInt(1, guahao.getPatientId());
pstmt.setString(2, new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()));
pstmt.setString(3, DateUtil.formatDate(guahao.getDate(), "yyyy-MM-dd"));
pstmt.setString(4, guahao.getOfficeName());
pstmt.setString(5, guahao.getGhDesc());
return pstmt.executeUpdate();
}
//定义要执行的sql语句
String sql="insert into t_ghinfo values(null,?,?,?,?,?)";
//从conn获取到PreparedStatement对象,用于执行数据库操作
PreparedStatement pstmt=con.prepareState,ment(sql);
//接下来的几行代码用于向sql语句中的几个?赋值
pstmt.setInt(1, guahao.getPatientId());
pstmt.setString(2, new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()));
pstmt.setString(3, DateUtil.formatDate(guahao.getDate(), "yyyy-MM-dd"));
pstmt.setString(4, guahao.getOfficeName());
pstmt.setString(5, guahao.getGhDesc());
//执行上面的sql语句,返回值是本次操作数据库的影响行数
return pstmt.executeUpdate();
这是往数据库里面添加数据的,最后返回的是添加了几行
楼主回家看看书再来吧!
看函数意思基本都能猜出点。 不懂了 可以百度下,这方面的东西
这是最简单的用jdbc与数据库交互,问号是占位符
基本是比较原始的更新数据库的方法