当前位置:Gxlcms > 数据库问题 > JDBC修改表数据

JDBC修改表数据

时间:2021-07-01 10:21:17 帮助过:29人阅读

package qddx.JDBC; 2 import java.sql.*; 3 public class UpdatebbsVo { 4 5 public void update(bbsVo vo){ 6 Connection conn = null; 7 PreparedStatement pst = null; 8 String sql = "update article set id=?,pid=?,rootid=?, title=?,cont=?,pdate=?,isleaf=? where id=?"; 9 try{ 10 conn = JDBC_Connection.getConnection(); 11 pst = conn.prepareStatement(sql); 12 pst.setInt(1, vo.getId()); 13 pst.setInt(2, vo.getPid()); 14 pst.setInt(3, vo.getRootid()); 15 pst.setString(4, vo.getTitle()); 16 pst.setString(5, vo.getCont()); 17 pst.setTimestamp(6, vo.getPdate()); 18 pst.setInt(7, vo.getIsleaf()); 19 pst.setInt(8, vo.getId()); 20 pst.executeUpdate(); 21 22 }catch(SQLException e){ 23 e.printStackTrace(); 24 }finally{ 25 JDBC_Connection.free(null, conn, pst); 26 } 27 } 28 public static void main(String[] args) { 29 // TODO Auto-generated method stub 30 UpdatebbsVo updatebbs = new UpdatebbsVo(); 31 int id = 13; 32 int pid = 1; 33 int rootid = 1; 34 String title = "蚂蚁也不好过"; 35 String cont = "蚂蚁也不好过"; 36 java.util.Date date = new java.util.Date(); 37 Timestamp pdate = new Timestamp(date.getTime()); 38 int isleaf = 0; 39 QueryById query = new QueryById(); 40 bbsVo bvo = new bbsVo(); 41 bvo = query.QuerybbsVoById(id); 42 if(bvo!=null){ 43 bbsVo vo = new bbsVo(); 44 vo.setId(id); 45 vo.setPid(pid); 46 vo.setRootid(rootid); 47 vo.setTitle(title); 48 vo.setCont(cont); 49 vo.setPdate(pdate); 50 vo.setIsleaf(isleaf); 51 updatebbs.update(vo); 52 System.out.println("修改了 id为 "+id+"的数据"); 53 }else{ 54 System.out.println("id 为 "+id+" 的数据不存在"); 55 } 56 } 57 58 }

 

JDBC修改表数据

标签:

人气教程排行