美文网首页
JDBC_PrepareUpdate

JDBC_PrepareUpdate

作者: 勇者与王者 | 来源:发表于2019-10-03 00:51 被阅读0次
    
    package Java_JDBC;
    
    import java.sql.*;
    
    /**
     * @Author quzheng
     * @Date 2019/10/3 0:05
     * @Version 1.0
     */
    public class JDBC_PrepareUpdate {
        public static void main(String[] args) throws ClassNotFoundException, SQLException {
    
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://192.168.8.14:3306/day22_JDBC";
            String user = "root";
            String password = "123456";
            Connection con = DriverManager.getConnection(url,user,password);
    
            String sql = "UPDATE sort set sname=?,sprice=? where sid=?";
            PreparedStatement pst = con.prepareStatement(sql);
            pst.setObject(1,"汽车美容");
            pst.setObject(2,49988);
            pst.setObject(3,7);
    
            int row = pst.executeUpdate();
    
            pst.close();
    
    
            String search = "select * from sort";
            PreparedStatement pstSearch = con.prepareStatement(search);
            ResultSet rs = pstSearch.executeQuery();
    
            while (rs.next()){
                System.out.println(rs.getString("sid")+
                        "   "+rs.getString("sname")+
                        "   "+rs.getString("sprice")+
                        "   "+rs.getString("sdesc"));
            }
    
    
            rs.close();
            pstSearch.close();
            con.close();
    
        }
    }
    
    
    

    相关文章

      网友评论

          本文标题:JDBC_PrepareUpdate

          本文链接:https://www.haomeiwen.com/subject/ruzrpctx.html