How to execute sql query stored in  a variable

Hi
define query = 'select * from abc;'
then how to execute this defined variable query.
Thanks,
Shyam

EXECUTE IMMEDIATE mmy_sql --(variable
INTO     mmy_default_bill_type;
by kumar.

Similar Messages

  • How to execute SQL Query in Code behind Using infopath 2010?

    Hi,
    I've repeatable on infopath form, and want bind it throuth code behind from SQL table. My question is that how to execute SQL Query in code behind from infopath as well as how would get Query result to bind repeatable control?
    Thanks In Advance
    Shoeb Ahmad

    Hello,
    You first need to add new SQL DB connection then you need execute connection from code behind.
    See below link to create new connection
    http://office.microsoft.com/en-in/infopath-help/add-a-data-connection-to-a-microsoft-sql-server-database-HP010092823.aspx:
    http://www.bizsupportonline.net/infopath2010/connect-infopath-2010-sql-server-2008-table.htm
    Then use below code to execute this connection:
    AdoQueryConnection conn = (AdoQueryConnection)(this.DataConnections["Data connection name"]);
    string origCommand = Select * from tablename;
    conn.Command = origCommand;
    conn.Execute();
    Finally bind your table:
    http://www.bizsupportonline.net/infopath2007/4-way-programmatically-add-row-repeating-table.htm
    http://stevemannspath.blogspot.in/2010/09/infopath-20072010-populate-repeating.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to Execute SQL Server stored procedure through SQL Developer?

    Hi,
    I was successful in connecting SQL Server database using SQL Developer. I am able to see all the objects such Tables,Views & Procedure and also can query data using sql Query. But when it comes to executing procedure there's no option to achieve this. I tried "Exec |<Execute Procedure> Proc_name" but unfortunately both statement threw Errors.
    Please suggest about other alternates.
    Thanks in Advance,
    AP

    Hi,
    I was successful in connecting SQL Server database using SQL Developer. I am able to see all the objects such Tables,Views & Procedure and also can query data using sql Query. But when it comes to executing procedure there's no option to achieve this. I tried "Exec |<Execute Procedure> Proc_name" but unfortunately both statement threw Errors.
    Please suggest about other alternates.
    Thanks in Advance,
    AP

  • How to Execute  sql query in PL/SQL ( a variable) with out using Cursor or REF cursor

    Hi
    I am building a dynamic query based on some conditions
    as an example
    v_query varchar2(2000);
    x1 varchar2(20);
    y1 varchar2(20);
    z1 varchar2(20);
    v_query := ' Select x,y,z into x1,y1,z1 From ... ';
    Is there any way to execute the query with out using cursor or ref cursor..
    Thanks
    Arun

    Both Tod and Eric provided valid responses given the format of the queory you supplied. Howver, if you want to use dynamic sql in either way, you need to be absolutely certain that your query will always only return a single row (e.g. SELECT COUNT(*) FROM mytable), because if it retuns more than one, your procedure will break unless you have an exception handler to handle either TOO_MANY_ROWS or OTHERS.
    If you want to pull in a lot of data without walking a cursor, you should look at the BULK COLLECT options.

  • How to execute SQL Query from the Crystal report X1

    Dear All,
    I am using crystal report X1. In my application am creating run time MS Access tables and giving table name at run time based on my requirement . From these tables I want to fetch data based on some condition and to display using crystal report X1. I have never used the SQL Queries in the Crystal reports. Please help me out.
    Thanks and Regards,
    Rahaneef T

    Please note;
    This forum is dedicated to all other development-related questions which are not directly addressed by other forums. This includes Business Objects SDKs, products, or technologies which do not fall under BusinessObjects Enterprise, BusinessObjects Edge, Crystal Reports Server, or Crystal Reports (for example Desktop Intelligence SDK, Universe Designer SDK, Portal Integration Kits, Java User Function Libraries, and other third party technologies or development languages).
    This looks more like a Crystal Reports design issue?
    Ludek

  • How Can I Execute Sql Query in Managed bean?

    Hi,
    I want to execute sql query in managedbean and get the query result. How can I do?
    Best wishes!

    You can do this by having current Database connection your application is using like this
    public static synchronized DBTransaction getDBTransaction(){
    FacesContext ctx = FacesContext.getCurrentInstance();
    ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
    BindingContext bc = (BindingContext)vb.getValue(ctx.getCurrentInstance());
    DataControl dc = bc.findDataControl("AppModuleDataControl");
    ApplicationModuleImpl am = ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());
    return am.getDBTransaction();
    and then user DBTransaction object to create Statement and PreparedStatement you can find those in java doc.

  • How to execute the parametered stored procedure in sql *plus ?

    how to execute the parametered stored procedure in sql *plus ?
    my storedprocedure format
    CREATE OR REPLACE PROCEDURE SMS_SELECTMPLOYEE
    (empDOB out date, empEmpName out varchar2)
    thanks & regards
    mk_mur

    Oh, sorry... making many reading-too-fast mistakes today...
    You can't declare date variables in SQL*Plus (seel help var), but you can cast to varchar2:
    TEST> CREATE OR REPLACE PROCEDURE SMS_SELECTMPLOYEE (empDOB out date, empEmpName out varchar2) IS
      2  d date := sysdate;
      3  e varchar2(10) := 'bob';
      4  begin
      5  empdob := d;
      6  empempname := e;
      7  end;
      8  /
    Procedure created.
    TEST> var d varchar2(30)
    TEST> var n varchar2(30)
    TEST> call  SMS_SELECTMPLOYEE(:d,:n);
    Call completed.
    TEST> print d n
    D
    11/07/06
    N
    bobYoann.

  • Executing SQL-query based on user input in text-box on APEX page

    Hi,
    I'm new to developing in APEX, and I encountered a problem...
    Is it even possible to make such thing: use text area for input of some SQL-query and then execute it on my schema and show results in report item? And if the answer is yes, can somebody provide me tips on how to do that?
    Thanks in advance.

    Denes Kubicek wrote:
    I think this example shows something similar:
    https://apex.oracle.com/pls/apex/f?p=31517:91
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    https://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------I see there is executing stored queries example, and text area showing executed one, but not quite understand how to sent sql-query directly from text input, based on your example :/

  • Executing a query stored ina file

    Hello all,
    I need to execute a query stored in a file through pl/sql program
    for eg: i have a query "select sysdate from dual;" stored in a file date.sql. this file is kept under default location oracle/bin directory. this has to be done through a plsql program . How can i achieve this
    Regards,
    Kiran

    we cannot execute a query stored in a file through pl/sql program. Instead use UTL package to read the script (in which seprate the script using ';' as delimiter or new line) and assign it to a variable in pl/sql program, then use the execute immediate command to execute the SQL.
    or store the required script in a procedure, call the SP in plsql program.
    Twinkle

  • How to Use SQL Query having IN Clause With DB Adapter

    Hi,
    I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
    Thanks

    invoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter

  • Please Suggest...How to execute SQL quiries in JDeveloper using BPEL????

    Hi All,
    I am very new user of Oracle JDeveloper and BPEL. I am trying to develop a process flow in JDeveloper using BPEL and get stuck when I was trying to execute a SQL quiry in the flow.
    How to execute SQL quiries using JDeveloper and BPEL?????????????
    Possibilities might be..
    1.Configring Database Adapter
    2.Using Java Embedded activities of BPEL
    However, any of the above mentioned way is not clear with me how to implement it to get the query run in the process flow.
    It will be great if anyone could help me with this concept....
    Thanks in advance
    -Prabha
    Edited by: user10259700 on Sep 15, 2008 3:48 AM

    Hi,
    though BPEL has its development environment in JDeveloper, it has its own forum
    BPEL
    Frank

  • Execute SQL query in JavaBean

    I want to execute SQL query in the JavaBean.
    Is there any problem in the following code.
    There is no error message, but the database do not update. And I try to use JSP , it is ok. What is the problem in JavaBean ??
    How to execute SQL in JavaBean ???
    Please help ! Thank you !
    test.jsp - call UserTrace.java
    UserTrace.java - execute SQL
    Code:
    ** test.jsp **
    <%@ page language="java" contentType="text/html" %>
    <%@ page import="user.*, java.util.*" %>
    <jsp:useBean id="usertrace" class="user.UserTrace" scope="session" />
    <%
    if (session.isNew())
         session.setAttribute("usertrace", usertrace);
         session.setMaxInactiveInterval(15);
    %>
    ** UserTrace.java **
    package user;
    import java.util.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.beans.*;
    import java.sql.*;
    import user.*;
    public class UserTrace implements javax.servlet.http.HttpSessionBindingListener {
         private Connection con = null;
         Statement stmt = null;
         ResultSet rs = null;
         String sql;
         public void valueBound(HttpSessionBindingEvent event) {
         public void valueUnbound(HttpSessionBindingEvent event) {
              try {
                   Class.forName("org.gjt.mm.mysql.Driver");
                   con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=abc&password=abcd");
                   stmt = con.createStatement();
                   sql = "insert into list(username, session_id) values ('mary', 'xxxxxxxxx')";
                   int count = stmt.executeUpdate(sql);
              catch (ClassNotFoundException e) {
              catch (SQLException e) {
    }

    Hi,
    U can use the following code:
    /********** IMPORTING PACKAGES AND CLASSES *******/
    // General package id
    package id;
    //Import the Vector class as this bean handles Vector.
    import java.util.Vector;
    //Import the SQL class to create the connections,statement,resultset etc.,
    import java.sql.*;
    //Import the SQL Types to call the setNull Method.
    import java.sql.Types.*;
    /* Main Class */
    public class dataBean
    /*********** Global Declarations ********/
    // To create the connection object
    Connection con;
    // To create the Statement object
    Statement stmt;
    // To create the PreparedStatement object
    PreparedStatement psmt;
    // To Handle the ResultSet
    ResultSet rs;
    // Most of the method need to hold the querystring for which qryString variable declare globally.
    String qryString=null;
    /************ METHODS **************/
    /* To set the connection object
         con - Connection object
    public void setConnection(Connection con)
    try
         this.con = con;
         catch(Exception e)
    /* insertRecord with column type argument
    tblNameString - Name of the Table
         dataVector - vector contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
         colType - String array contains type of all the fields.                    
    return true -     if record inserted successfully
         fase - if insertion fails                    
    public boolean insertRecord(String tblNameString,Vector dataVector,String colType[])
    boolean sucFlag=false;
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<fieldCount-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
    qryString = "insert into "+tblNameString+" values ("+commaString+")";
    psmt = con.prepareStatement(qryString);
    for(int i=0;i<colType.length;i++)
    if (colType.equals("I"))
    psmt.setInt(i+1,Integer.parseInt(dataVector.elementAt(i).toString()));
    else if (colType[i].equals("F"))
    psmt.setFloat(i+1,Float.parseFloat(dataVector.elementAt(i).toString()));
    else if (colType[i].equals("S") || colType[i].equals("D"))
    psmt.setString(i+1,dataVector.elementAt(i).toString());
    else if (colType[i].equals("IN")||colType[i].equals("FN"))
    psmt.setNull(i+1,java.sql.Types.NUMERIC);
    else if (colType[i].equals("SN"))
    psmt.setNull(i+1,java.sql.Types.VARCHAR);
    else if (colType[i].equals("DN"))
    psmt.setNull(i+1,java.sql.Types.DATE);
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    catch(Exception e)
    return sucFlag;
    /* insertRecord without column type argument
    tblNameString - Name of the Table
         dataVector - vector contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
    return true -     if record inserted successfully
         fase - if insertion fails                    
    public boolean insertRecord(String tblNameString,Vector dataVector)
    boolean sucFlag=false;
    Vector colType = getColumnType(tblNameString);
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<fieldCount-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
    qryString = "insert into "+tblNameString+" values ("+commaString+")";
    psmt = con.prepareStatement(qryString);
    for(int i=0;i<colType.size();i++)
    if (colType.elementAt(i).toString().equals("I"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setLong(i+1,Long.parseLong(dataVector.elementAt(i).toString()));
    else if (colType.elementAt(i).toString().equals("F"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setDouble(i+1,Double.parseDouble(dataVector.elementAt(i).toString()));
    else if (colType.elementAt(i).toString().equals("S"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.VARCHAR);
                   else               
         psmt.setString(i+1,dataVector.elementAt(i).toString());
    else if (colType.elementAt(i).toString().equals("D"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(i+1,java.sql.Types.DATE);
                   else               
         psmt.setString(i+1,dataVector.elementAt(i).toString());
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    catch(Exception e)
    return sucFlag;
    /* insert particular fields
    tblNameString - Name of the Table
         dataVector - vector which contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
         colType - String array contains type of all the fields.                    
    return true -     if record inserted successfully
         fase - if insertion fails                    
    public boolean insertRecordPart(String tblNameString,Vector dataVector,String colType[])
    boolean sucFlag=false;
    String fieldString=" ";
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<(fieldCount/2)-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
         String valueString[]= new String[fieldCount];
         for (int i=0,j=0;i<fieldCount;i+=2,j++)
                   fieldString=fieldString+dataVector.elementAt(i)+",";
                   valueString[j]=dataVector.elementAt(i+1).toString();
              if (fieldString.substring(fieldString.length()-1,fieldString.length()).equals(","))
              fieldString=fieldString.substring(0,fieldString.length()-1);
    qryString = "insert into "+tblNameString+"("+fieldString+") values ("+commaString+")";
    psmt = con.prepareStatement(qryString);
              for (int i=1,j=0;i<fieldCount;i+=2,j++)
    if (colType[j].equals("I"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setInt(j+1,Integer.parseInt(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("L"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setLong(j+1,Long.parseLong(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("F"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setFloat(j+1,Float.parseFloat(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("DB"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.NUMERIC);
                   else               
         psmt.setDouble(j+1,Double.parseDouble(dataVector.elementAt(i).toString()));
    else if (colType[j].equals("S"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
              psmt.setNull(j+1,java.sql.Types.VARCHAR);
                   else               
         psmt.setString(j+1,dataVector.elementAt(i).toString());
    else if (colType[j].equals("D"))
              if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
         psmt.setNull(j+1,java.sql.Types.DATE);
                   else               
         psmt.setString(j+1,dataVector.elementAt(i).toString());
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    catch(Exception e)
    return sucFlag;
    /* Get Column Type of require table fields
    tblNameString - Name of the table
    return vector which contains the column types of the desired table
    public Vector getColumnType(String tblNameString)
    int colCount = 0;
         String locString="";
         Vector colVector = new Vector();
    try
         qryString = "select DATA_TYPE from user_tab_columns where table_name=? ORDER BY COLUMN_ID";
    psmt = con.prepareStatement(qryString);
         psmt.setString(1,tblNameString.toUpperCase());
         rs = psmt.executeQuery();
         while (rs.next())
         colCount = rs.getMetaData().getColumnCount();
              for(int i=1;i<=colCount;i++)
              locString = rs.getString(i);
              colVector.addElement(locString.equals("DATE")?"D":locString.equals("NUMBER")?"F":locString.equals("VARCHAR2")?"S":locString.equals("VARCHAR")?"S":"");
         rs.close();
         catch(Exception e)
         return colVector;
    /* update record
    tblNameString - Name of the Table
         dataVector - vector which contains the values according to the table order
         eg., element(0) has first field, element(1) has second field vice versa
         colType - String array contains type of all the fields.                    
         return true - if record successfully updated
         false - if Update fails
    public boolean updateRecord(String tblNameString,Vector dataVector,String colType[],String whereString)
    boolean sucFlag=false;
    String fieldString=" ";
    try
    String commaString = "";
    int fieldCount = dataVector.size();
    for (int i=0;i<fieldCount-1;i++)
    commaString +="?,";
    commaString+="?";
    if (fieldCount > 0)
         String valueString[]= new String[fieldCount];
         for (int i=0,j=0;i<fieldCount;i+=2,j++)
                   fieldString=fieldString+dataVector.elementAt(i)+"=?,";
                   valueString[j]=dataVector.elementAt(i+1).toString();
              if (fieldString.substring(fieldString.length()-1,fieldString.length()).equals(","))
              fieldString=fieldString.substring(0,fieldString.length()-1);
    qryString = "update "+tblNameString+" set "+fieldString+" "+whereString;
    psmt = con.prepareStatement(qryString);
    for(int i=0,vectorPos=1;i<colType.length;i++,vectorPos+=2)
    if (colType[i].equals("I"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setInt(i+1,Integer.parseInt(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("L"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setLong(i+1,Long.parseLong(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("F"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setFloat(i+1,Float.parseFloat(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("DB"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.NUMERIC);
                   else               
              psmt.setDouble(i+1,Double.parseDouble(dataVector.elementAt(vectorPos).toString()));
    else if (colType[i].equals("S"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.VARCHAR);
                   else               
              psmt.setString(i+1,dataVector.elementAt(vectorPos).toString());
    else if (colType[i].equals("D"))
              if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
              psmt.setNull(i+1,java.sql.Types.DATE);
                   else               
              psmt.setString(i+1,dataVector.elementAt(vectorPos).toString());
    int sucCnt = psmt.executeUpdate();
              if (sucCnt > 0) sucFlag=true;
    } // end of if
    } // end of try
    catch(Exception e)
         return false;
         return sucFlag;
    public ResultSet getResultSet(String selectString)
         try
              stmt = con.createStatement();
              rs = stmt.executeQuery(selectString);
         catch(Exception e)
         System.out.println(e.getMessage());
         finally
         return rs;
    /* Get Query Result
    selectString - Query
    return the result vector based on the querystring
    public Vector getResultVector(String selectString)
         Vector resVector = new Vector();
         try
              stmt = con.createStatement();
              rs = stmt.executeQuery(selectString);
              while (rs.next())
              resVector.addElement(rs.getString(1));
              resVector.addElement(rs.getString(2));
         catch(Exception e)
         System.out.println(e.getMessage());
         finally
         return resVector;
    /* return next consecutive number
    tablenName - Name of the table for which the number to be generated
         serialFiel - Name of the field for which the number to be generated
         whereString - where condition to filter the records if composite key found,
                        it can be empty if there is no composite primary key.
    startNumber - if there is no record exists in the table, set the starting number
    public String getCurrentSerial(String tableName,String serialField,String whereString,String startNumber)
    String queryString = "select max(to_number("+serialField+")) from "+tableName+" "+whereString;
    int maxSerial=0;
    try
    psmt = con.prepareStatement(queryString);
         rs = psmt.executeQuery();
         while (rs.next())
              maxSerial = rs.getInt(1);
         if (maxSerial < 0)
         maxSerial=Integer.parseInt(startNumber);
         else
              maxSerial+=1;
         rs.close();
    catch(Exception e)
    return String.valueOf(maxSerial);
    /* return next consecutive number
    tablenName - Name of the table for which the number to be generated
         serialFiel - Name of the field for which the number to be generated
         whereString - where condition to filter the records if composite key found,
                        it can be empty if there is no composite primary key.
         Note : if there is no record exists in the table, it starts with 1
    public String getCurrentSerial(String tableName,String serialField,String whereString)
    String queryString = "select max(to_number("+serialField+")) from "+tableName+" "+whereString;
    int maxSerial=0;
    try
         stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
    while (rs.next())
              maxSerial = rs.getInt(1);
         if (maxSerial < 0)
         maxSerial=1;
         else
              maxSerial+=1;
         rs.close();
    catch(Exception e)
    System.out.println("Error from max serialX:"+e.getMessage());
    return String.valueOf(maxSerial);
    /* return the currnent user name */
    public String getCurrentUser()
    Statement stmt=null;
    ResultSet rs=null;
    String queryString = "select user from dual";
    String userName = "";
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
              userName = rs.getString(1);
         rs.close();
    catch(Exception e)
    return userName;
    /* return current user along with server's current date
    example : userName#today
    public String getCurrentUserDate()
    Statement stmt=null;
    ResultSet rs=null;
    String queryString = "select user,to_char(sysdate,'dd-mon-yyyy') from dual";
    String userName = "";
    String todayDate= "";
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
              userName = rs.getString(1);
                   todayDate = rs.getString(2);
         rs.close();
    catch(Exception e)
    return userName+"#"+todayDate;
    /* return server's current date */
    public String getCurrentDate()
    Statement stmt=null;
    ResultSet rs=null;
    String queryString = "select to_char(sysdate,'dd-mon-yyyy') from dual";
    String todayDate= "";
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
                   todayDate = rs.getString(1);
         rs.close();
    catch(Exception e)
    return todayDate;
    /* return true if atleast one record found in the table
         tblName : Name of the table
         whereString : Where condition to filter the records
    public boolean isRecordExists(String tblName,String whereString)
    String queryString = "select count(1) from "+tblName+" "+whereString;
    boolean recFound = false;
    try
    stmt = con.createStatement();
         rs = stmt.executeQuery(queryString);
         while (rs.next())
         if (rs.getInt(1)==0)
                        recFound = false;
                   else
                        recFound = true;
         rs.close();
    catch(Exception e)
    return recFound;
         // round off decimal Places
    public String fixDecimal(String sourceString,int digits)
    String tmpText="",decimalPart="",returnText="";
    try
    sourceString = String.valueOf(Double.parseDouble(sourceString));
    tmpText = sourceString.substring(sourceString.indexOf(".")+1);
         if (tmpText.length() > digits)
         decimalPart = tmpText.substring(0,digits);
    if (Integer.parseInt(tmpText.substring(digits,digits+1))>=5)
         decimalPart = String.valueOf(Integer.parseInt(decimalPart)+1);
         tmpText = decimalPart;      
         if (decimalPart.length() > 3) // to check wheter 1000 reached, if yes add 1 to actual text      
              returnText = String.valueOf(Integer.parseInt(sourceString.substring(0,sourceString.indexOf(".")))+1);
         else
                   returnText = sourceString.substring(0,sourceString.indexOf("."))+"."+tmpText;
         else // if user entered decimal is with in 3 digits
         if (tmpText.equals("0"))
                   returnText = sourceString.substring(0,sourceString.indexOf("."));
              else               
                   returnText = sourceString.substring(0,sourceString.indexOf("."))+"."+tmpText;
    catch(Exception e)
    System.out.println(e.getMessage());
    return sourceString;
    System.out.println(returnText);
    return returnText;
    } // end of main class
    Access this Bean in JSP as follows:
    <%@ page language="java" %>
    <%@ page import="java.util.*"%>
    <%@ include file="../connectionSetup.jsp"%>
    <jsp:useBean id="dataBeanObj" class="id.dataBean"/>
    <html>
    <head>
         <title>ADDRESS MASTER FORM</title>
    <style type="text/css">      
    .tData
         font-family : sans-serif;
         font-size : 9px;
         font-weight : bolder;
         color : navy;
    .buttonStyle
         font-family : sans-serif;
         font-size :10px;
    </style>
    </head>
    <%
    dataBeanObj.setConnection(con);
    String curCode="";
         String consFld = request.getParameter("consfld")==null?"":request.getParameter("consfld");
         String cat = request.getParameter("cat")==null?"a":request.getParameter("cat").equals("a")?"a":"u";
    boolean updateFlag=false,isWrongCountry=false;
    String code="";
         String name="";
         String add1="";
         String add2="";
         String add3="";
         String state="";
         String country="";
         String zip="";
         String am_pcouncode="";
         String am_pareacode="";
         String am_psubcode="";
         String am_fcouncode="";
         String am_fareacode="";
         String am_fsubcode="";
         String am_phone="";
         String am_fax="";
         String email="";
         String notes="";
         String telex="";
         String mobile="";
         String popup="";
         code = request.getParameter("code")==null?"":request.getParameter("code");
         name = request.getParameter("name")==null?"":request.getParameter("name");
         popup = request.getParameter("popup")==null?"":request.getParameter("popup");
         String submitMode = request.getParameter("submit_mode")==null?"":request.getParameter("submit_mode");
         String editMode = request.getParameter("edit_hidden")==null?"null":request.getParameter("edit_hidden");
         if (name != null && !submitMode.equals("yes")) // ready to retrieve records
         if (!code.equals(""))
              rs = dataBeanObj.getResultSet("select am_code code,am_name name,am_address_1 add1,am_address_2 add2,am_address_3 add3,am_country country,am_state state,am_zip zip,am_phone phone,am_fax fax,am_e_mail email,am_notes notes,am_telex telex,am_mobile mobile from id_vms_address_master where am_code='"+code+"'");
              else
              rs = dataBeanObj.getResultSet("select am_code code,am_name name,am_address_1 add1,am_address_2 add2,am_address_3 add3,am_country country,am_state state,am_zip zip,am_phone phone,am_fax fax,am_e_mail email,am_notes notes,am_telex telex,am_mobile mobile from id_vms_address_master where upper(am_name)='"+name.toUpperCase()+"'");
         if (rs.next()) // if record found
              code = rs.getString("code");          //     retrieve code
              name = rs.getString("name");          //     retrieve name
              add1 = rs.getString("add1");          //     retrieve address 1
              add2 = rs.getString("add2");          //     retrieve address 2
              add3 = rs.getString("add3");          //     retrieve address 3
              country = rs.getString("country");          //     retrieve country
              state = rs.getString("state");          //     retrieve state
              zip = rs.getString("zip");          //     retrieve zip
              am_phone = rs.getString("phone");          //     retrieve phone
              am_fax = rs.getString("fax");          //     retrieve fax
              email = rs.getString("email");          //     retrieve email
              notes = rs.getString("notes");          //     retrieve notes
              telex = rs.getString("telex");          //     retrieve telex number
              mobile = rs.getString("mobile");          //     retrieve mobile number
         else if (submitMode.equals("yes")) // ready to submit
              code = request.getParameter("code");          //     get the input code
              name = request.getParameter("name");          //     get the input name
              add1 = request.getParameter("address1");     //     get the input address 1
              add2 = request.getParameter("address2");     //     get the input address 2
              add3 = request.getParameter("address3");     //     get the input address 3
              country = request.getParameter("country");     //     get the input country
              state = request.getParameter("state");          //     get the input state
              zip = request.getParameter("zip");          //     get the input zip
              am_pcouncode = request.getParameter("pcouncode");          //     get the input phone country code
              am_pareacode = request.getParameter("pareacode");          //     get the input phone area code
              am_psubcode = request.getParameter("psubscode");          //     get the input phone subscriber code
              am_fcouncode = request.getParameter("fcouncode");          //     get the input fax country code
              am_fareacode = request.getParameter("fareacode");          //     get the input fax area code
              am_fsubcode = request.getParameter("fsubscode");          //     get the input fax subscriber code
              am_phone = am_pcouncode+"-"+am_pareacode+"-"+am_psubcode;
              am_fax = am_fcouncode+"-"+am_fareacode+"-"+am_fsubcode;
              telex = request.getParameter("telex");          //     get the input telex
              mobile = request.getParameter("mobile");     //     get the input mobile
              email = request.getParameter("email");          //     get the input email
              notes = request.getParameter("notes");          //     get the input notes
              String colType[] = {"S","S","S","S","S","S","S","S","S","S","S","S","S","S"};
              Vector vec = new Vector();
              if (cat.equals("u"))
                   vec.addElement("am_code");          vec.addElement(code);          //     add code to vector element
              else
              curCode = dataBeanObj.getCurrentSerial("id_vms_address_master","am_code","");
                   vec.addElement("am_code");          vec.addElement(curCode);          //     Next Serial Generation
              vec.addElement("am_name");          vec.addElement(name);          //     add name to vector element
              vec.addElement("am_address_1");     vec.addElement(add1);          //     add address 1 to vector element
              vec.addElement("am_address_2");     vec.addElement(add2);          //     add address 2 to vector element
              vec.addElement("am_address_3");     vec.addElement(add3);          //     add address 3 to vector element
              vec.addElement("am_country");     vec.addElement(country);     //     add country to vector element
              vec.addElement("am_state");          vec.addElement(state);          //     add state to vector element
              vec.addElement("am_zip");          vec.addElement(zip);          //     add zip to vector element
              vec.addElement("am_phone");          vec.addElement(am_phone);          //     add phone to vector element
              vec.addElement("am_fax");          vec.addElement(am_fax);          //     add fax to vector element
              vec.addElement("am_e_mail");          vec.addElement(email);          //     add email to vector element
              vec.addElement("am_notes");          vec.addElement(notes);          //     add notes to vector element
              vec.addElement("am_telex");          vec.addElement(telex);          //     add telex to vector element
              vec.addElement("am_mobile");          vec.addElement(mobile);          //     add mobile to vector element
              if (dataBeanObj.isRecordExists("id_country_master"," where country_code='"+country+"'"))
                   if (cat.equals("u"))
                        // update the records
                        updateFlag = dataBeanObj.updateRecord("id_vms_address_master",vec,colType,"where am_code='"+code+"'");
                   else
                        // insert record
                        updateFlag = dataBeanObj.insertRecordPart("id_vms_address_master",vec,colType);
                   else
                        isWrongCountry=true;               
    %>
    The connectionSetup.jsp is as follows:
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ page import="javax.naming.*" %>
    <%@ page import="allaire.taglib.*" %>
    <%
         Connection con=null;
         PreparedStatement ps = null;
         Statement stmt=null;
         ResultSet rs=null;
    try
         String jrunDSN = null, lookupDSN = null;
         jrunDSN = request.getParameter("dsnvalue") == null ? "vms_test" : request.getParameter("dsnvalue");
         lookupDSN     = "java:comp/env/jdbc/" + jrunDSN;
         InitialContext ctx     = new InitialContext();
         DataSource     dsn      = (DataSource)ctx.lookup(lookupDSN);
         try
              if (application.getAttribute("connectionapplication") == null)
                   con = dsn.getConnection();
                   application.setAttribute("connectionapplication",con);
              else
              con = (Connection) application.getAttribute("connectionapplication");
         stmt = con.createStatement();
         catch(Exception e)
              con = dsn.getConnection();
              application.setAttribute("connectionapplication",con);
    catch(Exception e)
         out.println("<font face='arial' size='2'><center>Problem with database connection. Please contact your administrator</center></font>");
    %>
    In Connection setup.jsp u can change as u need.
    This is thru JNDI. This works fine for us in our projects.
    Bye.

  • How to execute SQL Quiries in BPEL using JDeveloper

    Hi All,
    I am very new user of Oracle JDeveloper and BPEL. I am trying to develop a process flow in JDeveloper using BPEL and get stuck when I was trying to execute a SQL quiry in the flow.
    How to execute SQL quiries using JDeveloper and BPEL?????????????
    Possibilities might be..
    1.Configring Database Adapter
    2.Using Java Embedded activities of BPEL
    However, any of the above mentioned way is not clear with me how to implement it to get the query run in the process flow.
    It will be great if anyone could hepl me with this concept....
    Thanks in advance
    -Prabha

    ... or perhaps just scan the last 5 posts before you post a new thread, in which case, you'd discover that someone else already asked Help needed in executing SQL query... and got the same answer

  • How does a SQL query work

    Hi all...
    How does a SQL query basically work? Is there any pseudocode for it?
    How ro calculate the cost of query?
    Can we find out what would be the execution time for a query before it is executed?
    Thanks in advance.
    Ameya

    Hi Avinash,
    Look closely mate!!!
    You have done set autotrace on... meaning you are executing the statement while i am doing set autotrace traceonly explain meaning the statement would never get executed actually.. oracle optimizer will just select the desired plan and will show the output..
    You can even ESTIMATE how many rows the qeury will return before even executing the statement using the same above tech.. i will show you how:
    The explain plan gives this -- as long as you are using the CBO (cost based
    optimizer). Doesn't matter if you have 1 or 50 tables. The last part of the
    plan is the estimate output.
    consider:
    SQL> set autotrace traceonly explain
    SQL> select e1.*, e2.* from emp e1, emp e2;
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=15 Card=196 Bytes=12544)
    1 0 MERGE JOIN (CARTESIAN) (Cost=15 Card=196 Bytes=12544)
    2 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=448)
    3 1 SORT (JOIN) (Cost=14 Card=14 Bytes=448)
    4 3 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=448)
    196 = 14 * 14 -- thats right....
    SQL> select emp.ename, mgr.ename from
    2 emp, emp mgr
    3 where emp.mgr = mgr.empno;
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=13 Bytes=208)
    1 0 MERGE JOIN (Cost=5 Card=13 Bytes=208)
    2 1 SORT (JOIN) (Cost=3 Card=14 Bytes=112)
    3 2 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=112)
    4 1 SORT (JOIN) (Cost=3 Card=14 Bytes=112)
    5 4 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=112)
    Here is estimated that about 13 rows would be returned...
    SQL> select count(*) from emp;
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1)
    1 0 SORT (AGGREGATE)
    2 1 INDEX (FULL SCAN) OF 'EMP_PK' (UNIQUE) (Cost=1 Card=14)
    one row...
    SQL> select ename, dname
    2 from emp, dept where emp.deptno = dept.deptno;
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=14 Bytes=252)
    1 0 NESTED LOOPS (Cost=5 Card=14 Bytes=252)
    2 1 TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=4 Bytes=44)
    3 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=98)
    14 rows...
    1 select ename, dname
    2* from emp, dept where emp.deptno = dept.deptno and emp.ename like '%A%'
    SQL> /
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=18)
    1 0 NESTED LOOPS (Cost=2 Card=1 Bytes=18)
    2 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=1 Bytes=7)
    3 1 TABLE ACCESS (BY INDEX ROWID) OF 'DEPT' (Cost=1 Card=4 Bytes=44)
    4 3 INDEX (RANGE SCAN) OF 'DEPT_IDX' (NON-UNIQUE)
    1 rows.....
    and this was all done without executing the query. See EXPLAIN plan and the
    PLAN_TABLE.

  • How to use sql query in java ?

    i don't know how to use sql query in java code.
    who can give me some advice?
    thanks

    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

Maybe you are looking for

  • Add a link to a form in FormsCentral

    I have created a very basic form that I intent to use as a fillable PDF form.   This will not be distributed.   The form is complete and before I save it as a PDF, I need to add a link to my e-mail address.    I see the link feature in the toolbar bu

  • I was erasing my Macbook pro using disk utility and it is frozen? Help!?

    Ok So I was erasing my macbook to restore it using the disk utility. When I clicked erase it began the proccess. It has been stuck staying unmounting disk for a few hours now and the mouse wont move. I am afraid to restart it because I dont want to m

  • I just discovered that Baudi has been added to my safari search options and I don't want it. How do I remove it?

    I want to remove BAIDU from my Safari browser search engine choices. I read to go to "applications" select "toolbars" and select "uninstall Baidu" . The problem is  "toolbars" is not on my list of "applications". How do I remove Baidu?  I don't know

  • Perofrmance issue on data fetch from db table

    Dear Experts, I have one requirement which explained below step wise. Step - 1 : I have a parameter on selection screen from where i ll get my ebeln value (User Input field) and that ebeln i ll check in ekpo table for validations.               If va

  • I can't validate my VPP "facilitators"

    I'm creating a district Volume Purchase Program. I've created two facilitators and can login to the accounts at the Volume Purchase store for education. I'm then prompted to click a link to validate the account. I've tried both the school and my home