Package net.hasor.db.jdbc.core

Examples of net.hasor.db.jdbc.core.JdbcTemplate


        Connection conn = DataSourceUtils.getConnection(getDataSource());//申请连接
        {
            /*T1*/
            String insertUser = "insert into TB_User values(?,'默罕默德','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘默罕默德’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        {
            /*T2*/
            this.executeTransactional();
            Thread.sleep(1000);
        }
        { /*T1*/
            String insertUser = "insert into TB_User values(?,'赵飞燕','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘赵飞燕’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        DataSourceUtils.releaseConnection(conn, getDataSource());//释放连接
    }
View Full Code Here


        }
        {
            /*T1*/
            String insertUser = "insert into TB_User values(?,'默罕默德','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘默罕默德’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        {
            /*T2*/
            this.executeTransactional();
            Thread.sleep(1000);
        }
        {
            /*T1*/
            String insertUser = "insert into TB_User values(?,'赵飞燕','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘赵飞燕’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        {
            /*T1-Commit*/
            System.out.println("commit T1!");
View Full Code Here

        }
        {
            /*T1*/
            String insertUser = "insert into TB_User values(?,'默罕默德','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘默罕默德’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        {
            /*T2*/
            this.executeTransactional();
            Thread.sleep(1000);
        }
        {
            /*T1*/
            String insertUser = "insert into TB_User values(?,'赵飞燕','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘赵飞燕’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        {
            /*T1-Commit*/
            System.out.println("commit T1!");
View Full Code Here

    @Test
    public void entity_QueryTest() throws SQLException {
        System.out.println("--->>entity_QueryTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        List<TB_User> userList = jdbc.queryForList("select * from TB_User", TB_User.class);
        HasorUnit.printObjectList(userList);
    }
View Full Code Here

    @Test
    public void simpleParam_QueryTest() throws IOException, URISyntaxException, InterruptedException, SQLException {
        System.out.println("--->>simpleParam_QueryTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        List<Map<String, Object>> userList = jdbc.queryForList("select * from TB_User where userUUID like ?", "76%");
        HasorUnit.printMapList(userList);
    }
View Full Code Here

        Connection conn = DataSourceUtils.getConnection(getDataSource());//申请连接
        {
            /*T1*/
            String insertUser = "insert into TB_User values(?,'默罕默德','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘默罕默德’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        {
            /*T2*/
            this.executeTransactional();
            Thread.sleep(1000);
        }
        { /*T1*/
            String insertUser = "insert into TB_User values(?,'赵飞燕','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
            System.out.println("insert new User ‘赵飞燕’...");
            new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
            Thread.sleep(1000);
        }
        DataSourceUtils.releaseConnection(conn, getDataSource());//释放连接
    }
View Full Code Here

    @Test
    public void testCallable() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>testCallable<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        //
        //        int flowID = jdbc.execute(new ConnectionCallback<Integer>() {
        //            public Integer doInConnection(Connection con) throws SQLException, DataAccessException {
        //                String callSQL = "exec PR_BuildFlowTID ?,?";
View Full Code Here

    @Test
    public void simple_UpdateJDBCTest() throws SQLException {
        System.out.println("--->>simple_UpdateJDBCTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
    }
View Full Code Here

    @Test
    public void simple_InsertJDBCTest() throws SQLException {
        System.out.println("--->>simple_InsertJDBCTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        System.out.println(jdbc.queryForInt("select count(*) from TB_User where userUUID='deb4f4c8-5ba1-4f76-8b4a-c2be028bf57b'"));
        //
        String insertUser = "insert into TB_User values('deb4f4c8-5ba1-4f76-8b4a-c2be028bf57b','安妮.贝隆','belon','123','belon@hasor.net','2011-06-08 20:08:08');";
        jdbc.execute(insertUser);//执行插入语句
        //
        System.out.println(jdbc.queryForInt("select count(*) from TB_User where userUUID='deb4f4c8-5ba1-4f76-8b4a-c2be028bf57b'"));
    }
View Full Code Here

    @Test
    public void baseInsertJDBCTest() throws SQLException {
        System.out.println("--->>baseInsertJDBCTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        String batchInsert = "insert into TB_User values(:ID,:Name,:Account,:Pwd,:Email,:RegTime);";
        //
        showUserCount(jdbc);//显示当前用户总数
        int count = 10;
        Map<String, Object>[] batchValues = new Map[count];
        for (int i = 0; i < count; i++) {
            batchValues[i] = new HashMap<String, Object>();
            batchValues[i].put("ID", UUID.randomUUID().toString());
            batchValues[i].put("Name", String.format("默认用户_%s", i));
            batchValues[i].put("Account", String.format("acc_%s", i));
            batchValues[i].put("Pwd", String.format("pwd_%s", i));
            batchValues[i].put("Email", String.format("autoUser_%s@hasor.net", i));
            batchValues[i].put("RegTime", new Date());
        }
        jdbc.batchUpdate(batchInsert, batchValues);//批量执行执行插入语句
        HasorUnit.printMapList(jdbc.queryForList("select * from TB_User"));
        //
        showUserCount(jdbc);//显示当前用户总数
    }
View Full Code Here

TOP

Related Classes of net.hasor.db.jdbc.core.JdbcTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.