Using Spring JdbcTemplate to extract one string

It would help a lot to know what your SQL query looks like, but assuming it’s something like SELECT STREET_NAME FROM table WHERE ID=1; CODE: public String getStreetNameById(int id) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = “SELECT STREET_NAME FROM table WHERE ID=?”; String streetName = (String) jdbcTemplate.queryForObject( sql, new Object[] { id }, … Read more

HsqlException: data exception

The maximum size of a VARCHAR column is user-defined. If the inserted data is larger than this, an exception is thrown. The example below defines a table with a VARCHAR(100) column, which limits the size to 100 characters. CREATE TABLE T (ID INT, DATA VARCHAR(100)) You can use a database manager and execute the SCRIPT … Read more

“Found: bit, expected: boolean” after Hibernate 4 upgrade

I worked this out by adding columnDefinition = “BIT” to the @Column line. @Basic @Column(name = “B”, columnDefinition = “BIT”, length = 1) public boolean isB() { return b; } Its defined as a ‘BIT(1)’ in the DB as well. Also worked with TINYINT. This is the easiest solution I’ve found since the change is … Read more

How to initialize in-memory HSQLDB using script via Spring

If you are trying to work with in-memory databases and Spring, there is a new jdbc namespace for Spring 3 that makes working with embedded databases very easy. The best part is that it acts as a DataSource, so it can easily be dropped in to replace your existing dataSource bean. <jdbc:embedded-database id=”dataSource” type=”HSQL”> <jdbc:script … Read more

SQLite vs HSQLDB

SQLite is implemented in C, HSQL is implemented in Java. It should be more seamless and easy to integrate SQLite with an application project written in C or C++, whereas I would expect the HSQL technology is easier to integrate with a project written in Java. No doubt there are numerous other more subtle differences … Read more

How to see all the tables in an HSQLDB database?

The ANSI SQL92 standard for querying database metadata is contained within the INFORMATION_SCHEMA data structures. I have no idea whether your database supports this or not, but try the following: SELECT * FROM INFORMATION_SCHEMA.TABLES On further research, it appears that HSQLDB does support INFORMATION_SCHEMA, but with slightly non-standard naming. All of the tables have SYSTEM_* … Read more

How do I reset my database state after each unit test without making the whole test a transaction?

Since you are using Hibernate, you could use the property hibernate.hbm2ddl.auto to create the database on startup every time. You would also need to force the spring context to be reloaded after each test. You can do this with the @DirtiesContext annotation. This might add a bit extra overhead to your tests, so the other … Read more

Inspect in memory hsqldb while debugging

In your unit test or in the @Before / setUp() method, you can add the following line to launch the HSQL Database Manager: org.hsqldb.util.DatabaseManager.main(new String[] { “–url”, “jdbc:hsqldb:mem:testdb”, “–noexit” }); or for the improved Swing version with “more refinements” (but about same functionality) org.hsqldb.util.DatabaseManagerSwing.main(new String[] { “–url”, “jdbc:hsqldb:mem:testdb”, “–noexit” }); The DB manager lets you … Read more

Unsuccessful: alter table XXX drop constraint YYY in Hibernate/JPA/HSQLDB standalone

You can ignore these errors. Combination of create-drop and empty (which is the case always for in-memory) database produces these for every database object it tries to drop. Reason being that there is not any database objects to remove – DROP statements are executed against empty database. Also with normal permanent database such a errors … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)