Blog

- Showing all posts in category: Java

If you were familiair with Eclipse you know that when you would save java class it will build automatically. With IntelliJ you don't have to spam the CTRL + S combination anymore because it will save automatically but there is only one problem. Your class will not be compiled.
Some developers prefer to compile manually because of the performance of the IDE but it can trick you into weird behavior if you forget it once. Especially when developing microservices where you are running 5 instances of IntelliJ.

IntelliJ has the option to build project automatically, BUT it only works while not running / debugging. How sad that is.

The problem I was facing

I was developing a Spring Boot application using Spring Boot Developer Tools which comes with a neat feature where classes are being reloaded. The dev tools only restarts the ServletContext within seconds. The main problem was that it only happens when the class is being compiled. So in Intellij you had to trigger a build yourself while in Eclipse when you would save your class, it will compile automatically even when running.

In IntelliJ it is possible to override this behavior to build automatically even when the application is running.

The setting we want to override is this:

 

1. Open the registry

2. Look for compiler.automake.allow.when.app.running and enable it

Keep the description in your mind in case you get into weird behaviour.

Close and now you are done. 

 

 

 

 

I was trying to get a readable output of a stored procedure in Oracle SqlDeveloper but the lines were truncated after 90 characters. The tool didn't had the option to change the linesize for the script output.

It was faster for me to write this in Java to get the readable output of the query.

This code will print the column names with the record values.

      ResultSet rs = getResultSet()
      while (rs.next()) {
        int columnCount = rs.getMetaData().getColumnCount();
        List<String> results = new ArrayList<>();
		//Columnindex is one based.
        for (int i = 1; i <= columnCount; i++) {
          String columnName = rs.getMetaData().getColumnName(i);
          String value = rs.getString(i);
          results.add(columnName + "=" + value);
        }
        System.out.println(results);
      }