Package org.sql2o

Examples of org.sql2o.Connection.createQuery()


        boolean failed = false;

        Connection connection = sql2o.beginTransaction();

        try{
            connection.createQuery("insert into issue3table(val) values(:val)")
                .addParameter("val", "abcde").addToBatch()
                .addParameter("val", "abcdefg").addToBatch() // should fail
                .addParameter("val", "hello").addToBatch()
                .executeBatch().commit();
        }
View Full Code Here


        try{
            connection = sql2o.beginTransaction();

            String createTableSql = "create table test_table(id SERIAL, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_table (val) values(:val)";
            Long key = (Long)connection.createQuery(insertSql, true).addParameter("val", "something").executeUpdate().getKey(Long.class);
            assertNotNull(key);
            assertTrue(key > 0);
View Full Code Here

            String createTableSql = "create table test_table(id SERIAL, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_table (val) values(:val)";
            Long key = (Long)connection.createQuery(insertSql, true).addParameter("val", "something").executeUpdate().getKey(Long.class);
            assertNotNull(key);
            assertTrue(key > 0);

            String selectSql = "select id, val from test_table";
            Table resultTable = connection.createQuery(selectSql).executeAndFetchTable();
View Full Code Here

            Long key = (Long)connection.createQuery(insertSql, true).addParameter("val", "something").executeUpdate().getKey(Long.class);
            assertNotNull(key);
            assertTrue(key > 0);

            String selectSql = "select id, val from test_table";
            Table resultTable = connection.createQuery(selectSql).executeAndFetchTable();

            assertThat(resultTable.rows().size(), is(1));
            Row resultRow = resultTable.rows().get(0);
            assertThat(resultRow.getLong("id"), equalTo(key));
            assertThat(resultRow.getString("val"), is("something"));
View Full Code Here

        try {
            connection = sql2o.beginTransaction();

            String createSequenceSql = "create sequence testseq";
            connection.createQuery(createSequenceSql).executeUpdate();

            String createTableSql = "create table test_seq_table (id integer primary key, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_seq_table(id, val) values (nextval('testseq'), 'something')";
View Full Code Here

            String createSequenceSql = "create sequence testseq";
            connection.createQuery(createSequenceSql).executeUpdate();

            String createTableSql = "create table test_seq_table (id integer primary key, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_seq_table(id, val) values (nextval('testseq'), 'something')";
            Long key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);

            assertThat(key, equalTo(1L));
View Full Code Here

            String createTableSql = "create table test_seq_table (id integer primary key, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_seq_table(id, val) values (nextval('testseq'), 'something')";
            Long key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);

            assertThat(key, equalTo(1L));

            key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);
            assertThat(key, equalTo(2L));
View Full Code Here

            String insertSql = "insert into test_seq_table(id, val) values (nextval('testseq'), 'something')";
            Long key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);

            assertThat(key, equalTo(1L));

            key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);
            assertThat(key, equalTo(2L));
        } finally {
            if (connection != null) {
                connection.rollback();
            }
View Full Code Here

        try {
            connection = sql2o.beginTransaction();

            String createTableSql = "create table test_serial_table (id serial primary key, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_serial_table(val) values ('something')";
            Long key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);

            assertThat(key, equalTo(1L));
View Full Code Here

            String createTableSql = "create table test_serial_table (id serial primary key, val varchar(20))";
            connection.createQuery(createTableSql).executeUpdate();

            String insertSql = "insert into test_serial_table(val) values ('something')";
            Long key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);

            assertThat(key, equalTo(1L));

            key = connection.createQuery(insertSql, true).executeUpdate().getKey(Long.class);
            assertThat(key, equalTo(2L));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.