Pages

Monday, June 16, 2014

ORA-00904: "%text%": invalid identifier 00904. 00000 - "%s: invalid identifier"

A was trying a pretty basic command in SQL Developer and for some reason I got the following response that irritated me for almost an hour

 

ORA-00904: "%text%": invalid identifier

00904. 00000 -  "%s: invalid identifier"

*Cause:   

*Action:

Error at Line: 2 Column: 62

 

My query was pretty much similar to the following.

 

select * from <<table_name>> where <<column_name>> like “text”;

 

After a few trial and errors I identified the error. It was because of the double quotes around the text pattern that I was using. I replaced it with single quotes and things worked like charm. So as end result my query was like

 

select * from <<table_name>> where <<column_name>> like ‘text’;

 

Hope this helps some one J

 

Tuesday, June 10, 2014

Stuck with Unix Screen - A remedy

Stuck with Unix Screen - A remedy

 

I had been tinkering with the less and grep commands this morning and found that I got stuck with the PuTTY window. None of my commands seemed to work as they were getting in as some sort of text values. 0)0)

 

Exit, Clear nothing worked. Eventually received an expert advice that ctrl+c or ctrl+z would help you get back to your working directory and ctrl+c worked for me .

 

Happy to see the $ again EE-lol

 

Friday, June 6, 2014

Opening existing projects in eclipse - method 2

I knew a way to do it which I had posted in http://ozinisle.blogspot.com/2014/05/opening-existing-projects-in-eclipse.html. Unfortunately that did not help me this time. I had a complicated project with a complicated folder structure driven by many configuration/property files. And hence eclipse either gave me messages like it does not find the project or there is already a project by that name.

 

Thanks to an expert advice that I received. I think I am thankful enough that I am sharing it with you. I was asked to create  a new project in my workspace. A plain old “New Project” -> “Java Project”

 

That did the trick. Though it created a new project, it started displaying the underlying folder structure in the operating system.

 

Hurray that worked for me. So in simple words,

 

1.       Let me assume that we have a project named “MyComplexProjectWithNastyFolderStructure” in “D:\workspace”

2.       I have a workspace set in eclipse pointing to “D:\workspace”

3.       Now if the project “MyComplexProjectWithNastyFolderStructure” is visible in the workspace – hell why are you reading this post

4.       Still “MyComplexProjectWithNastyFolderStructure” is visible but you have a problem like, you have to remove it and get updated code from say “CVS”, then close it

5.       Go to the file system (OS) and do what you have to do, like backing up the existing project, deleting it or scolding it or whatever nice stuff you plan to do

6.       Come back to eclipse. Click “File->New->Java Project”

7.       Give the name to your Java Project as “MyComplexProjectWithNastyFolderStructure”

8.       Tada… the project gets created again and this time you can look at the changes that you have made in the file system

9.       If not, try refreshing it

10.   Hope you got what you wanted. If not, “Lord Vinayaka Bless You” – go bless others for me J :P

 

Hope this helps J

 


Thursday, June 5, 2014

getXMLString from an XML Node Object

Following is a simple function that would let you obtain the XML contents of a XML node in a string format. The packages that had been imported into the class are listed as follows. I hope these are available as a free download

 

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

 

public static String getXMLString(Node xmlNode){

              String xmlString = null;

              xmlString="<";

              xmlString+=xmlNode.getNodeName();

             

              NamedNodeMap attributes=xmlNode.getAttributes();

              int noOfAttributes=attributes.getLength();

              int itr=0;

             

              for (itr=0;itr<noOfAttributes;itr++)     {

                     Node attributeNode=attributes.item(itr);

                     xmlString+=" "+ attributeNode.getNodeName() + "=" + attributeNode.getNodeValue();

              }

              xmlString+=">";

             

              NodeList childNodes=xmlNode.getChildNodes();

              int noOfChildNodes=childNodes.getLength();

             

              if (noOfChildNodes==0)     {

                     xmlString+=xmlNode.getNodeValue();

              }      else   {

                     int childNodeItr=0;

                     for (childNodeItr=0;childNodeItr<noOfChildNodes;childNodeItr++)      {

                           xmlString += getXMLString(childNodes.item(childNodeItr));

                     }

              }

             

              xmlString+="</"+xmlNode.getNodeName()+">";

             

              return xmlString;

       }

 

 

Creating an XML Document node from XML string

Following method helps you convert XML String into a XML Document Object

 

import java.io.ByteArrayInputStream;

import java.io.InputStream;

 

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

 

import org.w3c.dom.Document;

      

public Document getXMLDoc(String xmlString) {

       InputStream is = new ByteArrayInputStream(xmlString.getBytes());

       DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

       DocumentBuilder dBuilder = null;

       Document doc = null;

       try {

              dBuilder = dbFactory.newDocumentBuilder();

              doc = dBuilder.parse(is);

       } catch (Exception e) {

              // TODO Auto-generated catch block

              // logger.error("Parsing exception iha xml traversal");

       }

      

       return doc;

}

      

You can use the doc object as follows

 

doc.getElementsByTagName(tagName)

 

 

Monday, June 2, 2014

Creating a jar file through eclipse

Its rather simple and straight forward to create a jar file using eclipse. I am employing an ant build file to do this stuff.

 

Create a project and add a class to it as follows

package com.self.jarTest;

 

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World");

    }

}

 

Now create a build.xml file in the root of your project folder with the following content

<project>

 

    <target name="clean">

        <delete dir="build"/>

    </target>

 

    <target name="compile">

        <mkdir dir="build/classes"/>

        <javac srcdir="src" destdir="build/classes"/>

    </target>

 

    <target name="jar">

        <mkdir dir="build/jar"/>

        <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">

            <manifest>

                <attribute name="Main-Class" value="com.self.jarTest.HelloWorld"/>

            </manifest>

        </jar>

    </target>

 

    <target name="run">

        <java jar="build/jar/HelloWorld.jar" fork="true"/>

    </target>

 

</project>

 

Now right click on the build.xml and click on “Run As -> 3.Ant Build -> Clean, Compile, run, jar -> Run“

 

That’s it you got your jar file J

 

Creating a jar file through command prompt

It gives me a feeling like I am interacting more with my computer than usual. I feel like those so called geek hackers in Action movies as I don’t see anything visually until I clean, compile and run my jar files lol. I know I am exaggerating stuffs here, but, its’ sometimes good to enjoy the little things in life you know J

 

Coming to the point, In order to create a file entirely through command prompt, one can possibly follow the forth coming steps to do it.

 

1.       Get to your project folder. In my case it was through

>>cd “projectFolderPath”

 

2.       Create your class file. I created one to print a statement as follows

 

package com.self.jarTest;

 

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World");

    }

}

 

3.       Create a build directory

>>md build\classes

 

4.       Psst. I don’t have admin rights on this stupid machine and so I can’t change my environment variables. So I did the following

>>"C:\program files\Java\jdk1.7.0_55\bin\javac.exe” –sourcepath src –d build\classes src\com\self\jarTest\HelloWorld.java

 

In your case, if your environment variables are set properly I assume it must be something similar to

>>javac –sourcepath src –d build\classes (path to your HelloWorld.java file)

 

5.       Now create a folder to put your jar file

>>md build\jar

 

6.       And finally create your jar file (* following line does include a ‘dot’ – ‘.’ – don’t omit it)

>>jar cfm build\jar\HelloWorld.jar mf –C build\classes .

 

@*%%*, My class path is not set properly and I can do nothing about it L So I did the following

>>"C:\program files\Java\jdk1.7.0_55\bin\jar.exe" cfm build\jar\HelloWorld.jar mf –C build\classes .

 

Vola, my jar file is created. Now to do the most meaning full stuff, I am speaking about the “Check if its working or not” theorem. I used the following line of command

>>java -jar "build\jar\HelloWorld.jar"

 

Wohooo…. It worked like charm. I got the following

>>Hello World

 

I know it seems like, I am getting exited for nothing. Who gives a damn J

Trouble shooting java.lang.UnsupportedClassVersionError

I encountered an error which stated ‘Exception in thread "main" java.lang.UnsupportedClassVersionError: …. Blah blah blah’ when I tried to run an class as a normal java application in eclipse. The code was fairly simple and hence I definitely had nothing to debug for errors. A little search revealed about the nature of the error and its fix which was again fairly simple and straight forward.

 

I used a default JRE which was included from JDK160_29 corresponding to a weblogic 12c server. But my compiler was set to Java 1.7

 

So all I had to do was change it to 1.6 and my code worked like charm J

 

So in summary the fix to my issue was File->Preferences->Java Compiler->’Compiler Compliance Level’ -> choose between 1.3 to 1.7 to suit your JRE version. In my case it was 1.6