I am getting Following when query executing on through web application
java.sql.SQLException: ORA-04031:
java.sql.SQLException: ORA-04031: unable to allocate 48784 bytes of shared memory ("shared pool","SELECT emplid levempid, '2...","Typecheck","qry_text : qcpisqt")
But same query is executing through TOAD properly.
Chances are very high that your Java code is not making use of bind variables. In that case each SQL statement is unique and will not be reused, thrashing the shared pool. It will become fragmented and finally results in the ORA-04031.
Restarting the database will only temporarily work, but eventually you will run into the same problems. Increasing the shared pool size and regularly restarting the database is not a real solution. Only real solution is to rewrite your SQL to use bind variables.
Here is an AskTom thread of someone experiencing something similar: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:528893984337
And a nice little program to track which SQL statements are not making use of bind variables can be found in this thread: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1163635055580
Hope this helps.
Regards,
Rob.