JFinal 分页查询 Connection conn=config.getConnection(); conn为null是怎么回事

/**
     * Paginate.
     * @param pageNumber the page number
     * @param pageSize the page size
     * @param select the select part of the sql statement 
     * @param sqlExceptSelect the sql statement excluded select part
     * @param paras the parameters of sql
     * @return Page
     */
    publicPage<M> paginate(intpageNumber,intpageSize, String select, String sqlExceptSelect, Object... paras) {
        Config config = getConfig();


        Connection conn = null;
        try{
            conn = config.getConnection();
            returnpaginate(config, conn, pageNumber, pageSize, select, sqlExceptSelect, paras);
        }catch(Exception e) {
            thrownewActiveRecordException(e);
        }finally{
            config.close(conn);
        }
    }


原因: model没绑定的时候 貌似会抱一个类似的错;.
解决方法:在BaseConfig中的插件配置configPlugin中进行DB映射(例如:arp.addMapping(tableName,primary Key,modelClass.class))。
SqlHelper.java连接数据库通用类... package org.jdbc.com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class SqlHelper { /** * 设置单例 */ public static SqlHelper instance = new SqlHelper(); /** * 设置单例的一个实例方法 * * @return */ public static SqlHelper getInstance() { if (instance == null) { synchronized (SqlHelper.class) { instance = new SqlHelper(); } } return instance; } /** * 得到MySql连接 * * @return */ public static Connection getMySqlConnection() { Connection conn = null; String url = "jdbc:mysql://127.0.0.1:3306/jdbc?useUnicode=true&characterEncoding=utf-8"; String user = "root"; String password = "root"; String driver="com.mysql.jdbc.Driver"; try { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { System.out.println("连接数据库出现异常" + e.getMessage()); } return conn; } /** * 得到MMSQL连接 * @return */ public static Connection getMMSQLConnection() { String url = "jdbc:sqlserver://localhost:1433;DatabaseName=jdbc"; String user = "sa"; String password = "sa"; String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Connection conn = null; try { Class.forName(Driver); conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { System.out.println("连接数据库出现异常" + e.getMessage()); } return conn; } /** * 得到Oracle连接 * @return */ public static Connection getOracleConnection() { String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl"; String user = "scott"; String password = "scott"; String Driver="oracle.jdbc.driver.OracleDriver"; Connection conn = null; try { Class.forName(Driver); conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { System.out.println("连接数据库出现异常" + e.getMessage()); } return conn; } /*** * 释放资源... * * @param rs * @param st * @param conn */ public static void Relesae(ResultSet rs, Statement st, Connection conn) { try { if (rs != null) rs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值