大型网站和小企业站优化思路,东平专业的网站制作,房地产楼盘微信网站建设营销方案,网站建设合同拟写JFinal框架操作oracle数据库#xff0c;需要在configPlugin()方法中配置链接oracle数据库的相关配置配置JFinal数据库操作插件#xff0c;configPlugin方法这里我加载jdbc.properties配置文件实在configConstant加载的Overridepublic void configConstant(Constants me) {loa…JFinal框架操作oracle数据库需要在configPlugin()方法中配置链接oracle数据库的相关配置配置JFinal数据库操作插件configPlugin方法这里我加载jdbc.properties配置文件实在configConstant加载的Overridepublic void configConstant(Constants me) {loadPropertyFile(jdbc.properties);//加载配置文件me.setDevMode(getPropertyToBoolean(config.devModel, false));me.setViewType(ViewType.JSP);me.setEncoding(UTF-8);}jdbc.properites配置文件oracle.driveroracle.jdbc.driver.OracleDriveroracle.urljdbc:oracle:thin:127.0.0.1 :1521:orcloracle.usernamescottoracle.passwordxiaohuconfig.devModeltrueOverridepublic void configPlugin(Plugins me) {ActiveRecordPlugin arpnull;String drivergetProperty(oracle.driver);String urlgetProperty(oracle.url);String usernamegetProperty(oracle.username);String passwordgetProperty(oracle.password);DruidPlugin dpnewDruidPlugin(url, username, password, driver);me.add(dp);arpnewActiveRecordPlugin(dp);//设置数据库方言arp.setDialect(new OracleDialect());arp.setContainerFactory(new CaseInsensitiveContainerFactory());//忽略大小写me.add(new EhCachePlugin());arp.addMapping(users, id,Users.class);me.add(arp);}需要注意一点的是由于oracle数据库中在创建表时会自动的将所有的字段自动转为大写因此在避免后面操作的时候出现大小写错误的相关异常这里需要配置忽略大小写的功能arp.setContainerFactory(new CaseInsensitiveContainerFactory());//忽略大小写如果不需要对数据库进行增加操作则必须配置忽略大小写如果不配置忽略大小写在保存源代码的该段代码中会出现属性id找不到的异常/*** Save model.*/public boolean save() {Config configgetConfig();Table tablegetTable();StringBuilder sqlnewStringBuilder();ListparasnewArrayList();config.dialect.forModelSave(table, attrs, sql, paras);// if (paras.size() 0) return false; // The sql insert into tableName() values() works fine, so delete this line// --------Connection connnull;PreparedStatement pstnull;int result0;try {connconfig.getConnection();if (config.dialect.isOracle())pstconn.prepareStatement(sql.toString(), new String[]{table.getPrimaryKey()});elsepstconn.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS);config.dialect.fillStatement(pst, paras);resultpst.executeUpdate();getGeneratedKey(pst, table);//如果不配置忽略大小写执行到这里会出现异常虽然可以添加到数据库但是这里报错界面还是会显示500错误getModifyFlag().clear();return result 1;} catch (Exception e) {throw new ActiveRecordException(e);} finally {config.close(pst, conn);}getGeneratedKey()源代码部分/*** Get id after save method.*/private void getGeneratedKey(PreparedStatement pst, Table table) throws SQLException {String pKeytable.getPrimaryKey();if (get(pKey) null || getConfig().dialect.isOracle()) {ResultSet rspst.getGeneratedKeys();if (rs.next()) {Class colTypetable.getColumnType(pKey);if (colType Integer.class ||colType int.class)set(pKey, rs.getInt(1));else if (colType Long.class ||colType long.class)set(pKey, rs.getLong(1));elseset(pKey, rs.getObject(1)); // It returns Long object for int colTypers.close();}}}set()源代码部分/*** Set attribute to model.* param attr the attribute name of the model* param value the value of the attribute* return this model* throws ActiveRecordException if the attribute is not exists of the model*/public M set(String attr, Object value) {if (getTable().hasColumnLabel(attr)) {//执行到这里返回falseattrs.put(attr, value);getModifyFlag().add(attr); // Add modify flag, update() need this flag.return (M)this;}throw new ActiveRecordException(The attribute name is not exists: attr);//抛出该异常}现在来说说如果不配置为什么会出现 The attribute name is not exists:这个异常这是因为oracle中的字段是大写的而set方法中传入的attr属性的值是小写而getTable()中的属性对应的就是oracle字段这些属性则是大写因此这里使用getTable().hasColumnLabel(attr)判断是否存在该字段就会找不到这时就会抛出该异常因此就必须配置忽略大小写的方法就不会出现该异常实体类package com.tenghu.core.model;import com.jfinal.plugin.activerecord.Model;public class Users extends Model{public static Users daonewUsers();}操作数据UsersusersnewUsers();users.set(id, users_sequence.nextval);users.set(username, 张三);users.set(pwd, sdfsdfs);users.save();ListtestListUsers.dao.find(select * from users);这里就完成了JFinal框架操作oracle数据库删除和修改就自己去测试了