//With JAVA
String quer="SELECT * FROM sample2 where 1=2";
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(quer);
ResultSetMetaData rsmd = rs.getMetaData();
int NumOfCol=0;
NumOfCol=rsmd.getColumnCount();
System.out.println("Query Executed!! No of Colm="+NumOfCol);