Useful SQL Queries

| No Comments

You might find the following queries quite handy for your day to day SQL operations:

1. Get the total number of records in a table:

SELECT COUNT(*) FROM TABLE_NAME;

SQL User queries in Oracle

| No Comments

Here are a few  useful user SQL code snippets in Oracle:

1. To create a user

CREATE USER username
IDENTIFIED BY password
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP;

2. Grant user privileges:

GRANT CONNECT, RESOURCE, CREATE SESSION, CREATE VIEW TO username;


3. Grant all privileges:

GRANT all privileges TO username;

4. Delete a user or to delete a user and the associated user schema

drop user username cascade;

This SQL Snippet get a list of all the tables under a user:

select * from user_objects where object_type = 'TABLE';

This SQL Snippet will get you a list of all the sequences in a DB Schema for the user tables

select * from user_sequences


This SQL Snippet will get you a list of all the view in a DB Schema for the user tables

select * from user_views;

Happy Coding :)

Finding out the Oracle Version using SQL

| No Comments
If you ever have to find out the version of Oracle using SQL, use the following SQL command and it will spit out all the details.

SQL
 SELECT * FROM V$VERSION;

OUTPUT

BANNER                                                          
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production                          
CORE    10.2.0.1.0    Production                                        
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production         
NLSRTL Version 10.2.0.1.0 - Production
----------------------------------------------------------------

Happy Coding :)

Changing the default port number in Apache Tomcat

| No Comments

I had to run two webservers on my machine at the same time. Since both of them used port 8080 , the easiest way to run the two servers at the same time was to modify the port number on one of them.

Here is how we can change the port number in Apache Tomcat:

1. Navigate to : Apache Software Foundation\Tomcat X.X\conf



tomcat 5.5 Port Number.png 2. Modify the Server.xml file:

<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" ... />

Modify this to another non-conflicting port ( I changed it to 8888)

Happy Coding

XML Manipulation in Flex and ActionScript

| No Comments
There are lots of crazy ways of manipulating XML in ActionScript.Here are a few simple tips and tricks on manipulating XML in Actionscript.

  1. Declaring an XML Variable: An XML variable can be created in ActionScript as follows :
                 var tempSearchXML:XML =     <searchCriteria>
                                                                <branchName>023</branchName>
                                                                <contfirstname></contfirstname>
                                                                 <contlastname></contlastname>
                                                                 <contmailsort></contmailsort>
                                                                 <contphone></contphone>
                                                             </searchCriteria>
                                         
2.  Preview an XML Variable : An XML variable can be previewed in an Alert Box by converting the XML to a string object
       
            Alert.show(tempSearchXML.toString());
           
3.  Getting the value of a Node in the XML:

           Alert.show(tempSearchXML.branchName.toString());

4.  Setting the Value of Node in the XML : The following code sets the value of a node 'contfirstname '.
 
            tempSearchXML.contfirstname ="Armaghan";

5.  Setting / Changing / Updating the Node Attribute in the XML: The following code snippet changes the name of a Node from 'contlastname' to 'lastname'.

            tempSearchXML.contlastname.setName("lastname") ;
           
5.  Delete a Node in the XML: The following code snippet deletes a Node called 'contphone' in the XML.

            delete tempSearchXML.contphone;

6.  Adding a Node in the XML: The following code snippet adds a Node called 'text' in the XML and sets its value at the same time.

            tempSearchXML.text ="Taylor" ;

Happy Coding :)

Dump the Ant build information to a log file

| No Comments

If you ever need to dump the build information from the command prompt console into a log file, just add a -logfile <filename>.log parameter after your build file call in the command prompt console and you're good to go.

Happy Coding :)

Default Value in QueryParam Annotations

| No Comments
In order to remove any null pointer exceptions while using RestEasy Annotations, you can always pass a default value and handle it appropriately in the Data Access Objects ( If you are using one. This ensures that there are no null pointer excpetions from the returning classes.

Here is a code snippet to do just this:

public StreamingOutput getUsersSummaryList(@QueryParam("active") @DefaultValue("0") String active  ){}

PermGen space error (Hibernate, JPA)

| No Comments

If you ever come across a PerGen space error in Hibernate or JPA...it refers to the java.lang.outfspacememoryerror (Your webapp is out of memory). PermGen is  used to store the class definations ( and I do mean all the Loaded Classes ). This error refers to the heap space being full due to the large number of classes.

Generally you can recover from these errors by restarting your WebServer. If you want to really fix it, do one of the following 2:

1. Hibernate: Change the hibernate.properties file from  "hibernate.bytecode.provider javassist" to hibernate.bytecode.provider cglib".

2. JPA:  Change the persistance.xml file from
<property name="hibernate.bytecode.provider" value="javaassist"/> to <property name="hibernate.bytecode.provider" value="cglib"/>

Happy Coding :)
Now all you LiveCycle documentation hunters can look at a single location to find all LiveCycle related information....on your desktop...thats right...and its actually true.

Adobe released Tour De LiveCycle yesterday, a comprehensive AIR app that locks all aspects of LiveCycle documentation on your desktop. It will remind you of Flex explorer in its look and feel but encompasses videos, presentations, tutorials and hands on examples on all aspects of livecycle (Data services, BAM, Workbench etc) .

TourDeLiveCycle1.PNGIt can be downloaded here: