update(实体类)的实现逻辑
根据实体类标注的表名找到数据库中的表名,根据实体类中的字段名对应表中的字段名
String sql = "update BASE_MENU set menuname ='"+menuname+"' ";
if(enable != null){
sql = sql + ", enable = "+ enable +" ";
}else {
sql = sql + ", enable = null ";
}
if(StringUtil.notIsEmpty(menuicon)){
sql = sql + ", menuicon = '"+ menuicon +"' ";
}else {
sql = sql + ", menuicon = '' ";
}这样子拼接sql
拼接执行的sql,如果实体类字段有值就在sql中设值,无值varchar类型设为' ',int类型设为null,datetime类型同varchar.UPDATE `cssjgxpt`.`act_ge_property` SET `REV_` = NULL WHERE `NAME_` = 'fsdbfng' UPDATE `cssjgxpt`.`aaa` SET `time` = '' WHERE `id` = 3
利用jdbc来执行sql
ResourceBundle resource = ResourceBundle.getBundle("config");
//调用静态方法直接获得键值对中值
String url = resource.getString("jdbc.url");//url
String user = resource.getString("jdbc.username");//url
String pwd = resource.getString("jdbc.password");//url
//1、加载驱动(固定写法)
Class.forName("com.mysql.jdbc.Driver");
//3、连接成功,数据库对象(固定写法)
Connection connection = DriverManager.getConnection(url, user, pwd);
//4、执行sql的对象(固定写法)
Statement statement = connection.createStatement();
//5、执行sql语句,返回结果集
String sql="拼接的sql语句";//sql查询语句
ResultSet resultSet = statement.executeUpdate (sql);