Tuesday, 26 May 2015

ECHO in a Command Prompt

Contents:

Introduction

As per the DOS shell, the ECHO command brings up the following when you type HELP ECHO

C:\>help echo

Displays messages, or turns command-echoing on or off.
  ECHO [ON | OFF]
  ECHO [message] 

Type ECHO without parameters to display the current echo setting.

Open a new Command prompt window and try the following:

ECHO without parameters

C:\>echo
ECHO is on.

ECHO [ON | OFF]

To turn Echo Off, try the below
C:\>echo off
_
You would notice that the prompt with the current path has now disappeared. Test the setting by typing in echo and press Enter. You would see the below:
 
echo
ECHO is off.

To turn Echo off, type the below and press Enter. You should now see your prompt with the current path being displayed:

echo on
C:/>

ECHO [message]

  • ECHO Static String

On the command prompt, try the below:
C:\>echo Hello World
Hello World

C:\>echo "Hello World"
"Hello World"

C:\>echo 'Hello World'
'Hello World'


In short, anything that follows the Echo will be displayed. You dont have to quote it. If you add quotes, you notice that the quotes themselves are also displayed.
  • ECHO with Variables

If your using variables, which you might do in a Command Prompt, then the below is useful

C:\>set STRING="HELLO WORLD"
C:\>echo %STRING%
"HELLO WORLD"

If your using Environment Variables for instance:
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.8.0_45
 


Thursday, 15 January 2015

Hibernate Errors - Unknown column 'column_name' in 'where clause'

Just thought I'd share this.

While writing your hibernate queries, if your Restriction and ProjectList contain the same column you could get "Unknown column 'column_name' in 'where clause'" something like below

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'y17_' in 'where clause'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1888)
    at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2213)
    ... 86 more


My code is as below:

criteria.add(Restrictions.in("code", accommodationCodes)); 

and later
 
projectionList.add(Projections.property("name"), "name");
projectionList.add(Projections.property("code"), "code");


Basically when your restriction and projection contain the same column, you will see this error. To get around this, all you have to do is change

criteria.add(Restrictions.in("code", accommodationCodes));

to

criteria.add(Restrictions.in("this.code", accommodationCodes));