SQL QUERY IN JSP PAGE

Dear Friends,
There is a table named as EXPENSES having fields as sl_no, name.
I want to find the MAXIMUM value of the sl_no.
For that i am using the query as " SELECT MAX(sl_no) FROM EXPENSES "
In JSP file my code is ......................
ResultSet rs= stmt.executeQuery(" SELECT MAX(sl_no) FROM EXPENSES ");
if(rs.next()) {
out.println(rs.getInt("sl_no"));
this out.println line throws a exception as "column not found"
My aim is just to find the maximu value of a field from a table by using the jsp as a front end.
So please reply me how can I slove that problem.

It should work: ID must be a table field.
StringBuffer buf = new StringBuffer(1024);
Statement stmt = connection.createStatement();
String ID = "2";
String val = null;
if (app != null) {
   buf.append("SELECT emp_name from table where ID  = " + "'" +ID + "'");
rs = stmt.executeQuery(buf.toString());
while (rs != null && rs.next()) {
   val = rs.getString(1);
}Message was edited by:
skp71

Similar Messages

  • SQL query with JSP and WML-parameters

    Hey,
    Could you help me?
    I'm trying to do the following. WML deck card 1 send parameter to same WML deck's card help. I try to read the parameter with JSP in card help by putting the parameter to SQL query, but it doesn't work. I can read the parameter with WML in card help. I can also print the value of the parameter with JSP if I generate WML with JSP.
    /*parameter sending from card 1 to card help*/
    out.println("<go href='#helpcard'>");
    out.println("<setvar name='valittukurssi' value='$(valittukurssi)'/>");
    /*parameter read with WML in card help */
    <p>Valitse kurssi.
    $valittukurssi</p>
    /'parameter read with JSP by generating WML with JSP*/
    out.println("<p>$valittukurssi</p>");
    /* SQL query with JSP */
    ResultSet uudettulokset = uusilause.executeQuery("select * from kurssi where lyhenne='$valittukurssi'");
    Thanks,
    Rampe

    You're problem is easy to fix. You're confusing WML variables with JSP variables. See below:
    >
    /*parameter sending from card 1 to card help*/
    out.println("<go href='#helpcard'>");
    out.println("<setvar name='valittukurssi'
    value='$(valittukurssi)'/>");
    Above you set a var that will work on the phone, not in JSP.
    /*parameter read with WML in card help */
    <p>Valitse kurssi.
    $valittukurssi</p>
    Yes the above does display the parameter, because it is a client side WML var, but you cannot use this variable in the JSP code (that's why your SWL fails).
    /'parameter read with JSP by generating WML with
    JSP*/
    out.println("<p>$valittukurssi</p>");Here's you're problem, the above line is EXACTLY the same as the one before it. When the container parses through this JSP code it translates the above line to:
    <p>$valittukurssi</p> on the WML page and the CLIENT uses it's local variable to display it.
    What you need and want is to have a variable that can be used in JSP code and output to your WML page. Here's how it's done:
    out.println("<go href='#helpcard'>");
    String some_name = "valittukurssi";
    out.println("<setvar name='"+some_name+"'
    value='$("+some_name+")'/>");
    //note that you may have to escape the ( and ) with a \
    //so we displayed the variable above into the WML page, now we can use it in the SQL query:
    /* SQL query with JSP */
    ResultSet uudettulokset =
    uusilause.executeQuery("select * from kurssi where
    lyhenne='"+some_name+"'");//the end of the command is: " ' " ) ;
    Frank Krul
    Got Node?

  • Sql Query in JSP

    Hi All
    Had a quick question about a SQL Query in a JSP - Can I duplicated an exact same record in a table with a new primary key without using the insert statement??
    Say for example I have the following table:
    OrderNo OrderName OrderType
    ======= ========== ========
    1 Books Books
    2 CDs CDs
    3 DVDs DVDs
    I want to make an exact copy of OrderNo 3 with new OrderNo 4, so that it will be something like:
    4 DVDs DVDs
    Any ideas friends??
    Later

    Thanks Nikki, you are right. Actually it is my fault, I framed the question in a wrong way. Well, I found out the solution for that and here is the answer
    insert into [tablename] (OrderNo) select 42506 from [sametablename] where OrderNo=42405

  • Handling sql query in jsp while extracing records from 3 tables

    hi to one and all,
    i want to implement the sql query given below in jsp in execute query statement . the query is working in sql but not when implemented using jsp. please help me in resolving this.
    Query
    SELECT e.Department , e.ETitle , s.basic , s.da, c.address1 , c.address2 from Employee e , Salary s , Contactdetails1 c where e.id = s.id and e.id =c.id

    It would help if you gave us a little more info to go on like;
    a) post your code
    b) post the error message the compiler is giving you

  • SQL Query in JSP with variable problem

    Researching this but I haven't found an answer yet. I want to pass a user variable to the SQL query. Anyone know how? Thought the form call out might work but it doesn't. Thanks!     <%
         String selectX = request.getParameter("choice");
         String pSQLStr = "SELECT asset, tenant FROM fritco WHERE asset = '::selectX::'";
              try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:MyDataSource", "username", "password");
              Statement stmt = con.createStatement();
              ResultSet result = stmt.executeQuery(pSQLStr);

    Yes.
    Use a Prepared Statement.
    Saves you from sql injection attacks.
    String selectX = request.getParameter("choice");
    String pSQLStr = "SELECT asset, tenant FROM fritco WHERE asset = ?";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:MyDataSource", "username", "password");
    PreparedStatement stmt = con.prepareStatement(pSQLStr);
    stmt.setString(1, selectX);
    ResultSet result = stmt.executeQuery(); Suggestions for improvements.
    - Set up a JNDI datasource to retrieve your connection from. WIll do connection pooling for you, rather than creating a new DB connection each time.
    - Don't have any sql code in your JSP at all - that should be in beans.
    - If sql code MUST be in your JSP, use a taglib for it like the JSTL sql taglib
    - Don't use scriptlet code (<% %>) in JSPs. If you want to run java code use beans/servlets.
    Cheers,
    evnafets

  • Cannot Change SQL Query in Master page

    I am testing out Flex 3 and when I add a new master
    page and try to click the "Edit Master Page" button to write a query, nothing happens.  Any ideas?

    hello shay,
    no i not use the setWhereClause methode,
    i set the complete sql query (included where clause) from my backing bean!
        public void setSqlQuery4Object(StringBuffer sqlStr){
            ObjectsVOImpl vo =(ObjectsVOImpl)findViewObject("ObjectsVO");                    // Get ViewObject
            vo.setFullSqlMode(vo.FULLSQL_MODE_AUGMENTATION);
            vo.setQuery(sqlStr.toString());
        }i set the vo.setFullSqlMode(vo.FULLSQL_MODE_AUGMENTATION); and my problem are solved.
    is this way correct ??
    Thomas

  • Sql query execution in jsp

    can u help me to print multiple rows resulted from a sql query using jsp.

    Map the ResultSet to a Collection of DTO's, use the JSTL's c:forEach tag to iterate through it inside a JSP page, use the HTML table, tr and td elements to present the data in a table.

  • 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.

  • Clear data in sql report region on page load....

    I have a sql report region.when i run the page the data getting populate on the screen because of the sql query. On page load i dont want to populate the data in screen.
    i have created the page process to clear cahe the page. but the data is not clearing from the screen.
    How to resolve this?
    Thanks & regards,
    Skud.

    Skud,
    you can create condition in report region query e.g. where 1 = :PXX_ITEM, and populate that item on click and then refresh report.
    Bt,
    Marko

  • How-To populate SELECT LIST default value from SQL Query

    OK, I've done my homework, and did not find my answer in the Forum, so here it is.
    I have a Page that displays fields from a SQL Query. The Page also has below that radiogroups, checkboxes, and Select Lists to allow the user to change values in the fields that are displayed at the top of the Region. I am able to pre-populate the radiogroups and checkboxes by performing a SELECT in the 'Source value or expression' of the Source area of the Page Item.
    However, I am unable to do the same for the Select List fields. Their default value ends up being the first value in the LOV ('-- None --' for NULL values). Source Used: Only when current value in session state is null. Source Type: SQL Query. Also, when I first go into the Page when running it, and check the Session State values, they are all null, so I don't understand why the field is not populated by the SQL Query statement as the radiogroups and checkboxes are.
    Any suggestions??? I've tried all sorts of combinations.

    Thank you for the suggestion.
    I had considered that, but cannot do so, because we are using Oracle Application Express more for development than for data containment.
    We have all our data in an Oracle 10.g DB which is separate from the OAEX server, and the OAEX app will reference that data via VIEWs and DB LINKs. We are doing so primarily as an added data security layer, where the data is housed separate from the app, in case the Web site is ever compromised. The data that can be viewed is restricted to a subset of the actual data that is available.
    Since the data is on a separate server, (I assume) we will not be able to set the source type to Database column, because (I asume) that is dependent upon the data being housed by the OAEX server.
    That still leaves me with having to populate the field with a SELECT statement from the Oracle DB. This unfortuneately is almost a show-stopper for me because of down-stream processing data requirements. Have not been able to come up with contingencies yet.

  • Interactive report - Function returning SQL query

    i notice that it is not possible to create an interactive report based on a function call. can anyone shed any light on why this is?
    also, is there a work around possible? i really dont want to store my SQL query inside a page in the application

    Craig,
    I tried the collection workaround as well but noticed that it gets incredible slow when data sets grow bigger. Depending on what you need maybe my solution is of help for you:
    I used multiple subpages with interactive reports, an iframe and a javascript function setting the iframe-src on the main page, see my last post on
    interactive report custom GO-Button (-process)
    Paul

  • How to find the backend  SQL query of the JSP page in OIC

    Does anybody how the best way to find the backend SQL QUERY of OIV JSP page?

    How To Generate Trace Files in in HTML/JSP (using Profile Option)
    •     • Note: This requires proper responsibility to set SQL Initialization statement using Profile option.      
         Step 1.     Login to the desired Form application.     
         Step 2.     Select +Profile >> System ('Find System Profile Values' screen will pop up)     
         Step 3.     Check 'User' and Type in the Username (in which the account for that user will be trace)     
         Step 4.     Type 'Initialization%' in the Profile box and Hit 'Find' (Click here for preview.)     
         Step 5.     In the User box, type the following statement and Hit 'Save' (Click here for preview)
         BEGIN FND_CTL.FND_SESS_CTL('','','TRUE','TRUE','','ALTER SESSION SET TRACEFILE_IDENTIFIER = TESTING MAX_DUMP_FILE_SIZE = 5000000 EVENTS ='||''''||' 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12'||'''');END;     
         Note:     specify any name you like to identify your trace, in this case, testing is the end name on the trace. You can also specify the amount of data allowable to be in the trace, in this case, 5000000 is the amount set. Make sure you hit 'Save' afterwards.[Quotes in the statement are all 'Single' quotes.]
              specifying TRACEFILE_IDENTIFIER value is mandatory when setting up the trace using the above profile option value
         Step 6.     Login to HTML / JSP page with username/password and start your flow. (Everything you do once login to HTML / JSP will get trace.)     
         Step 7.     Logout of HTML / JSP application once you completed with your flow.      
         Step 8.     Go back to the Profile option in the Form application and delete the Initialization SQL statement, and Hit 'Save'.     
         Step 9.     Log in to the database server or login server and retrieve your trace file.
         Identify and retrieve the trace file using the tracefile_identifier specified in Step 5.
         In this case the tracefile_identifier is “TESTING”. (Click here for Trace file locations) *     
         Note:     If you need to regenerate your trace or tracing a new flow, then repeat Step 1 to Step 8. To avoid self-confusion, choose a different name for your trace identifier everytime you set to trace.     
         Step 10.     See TKPROF section on how to format trace file into readable text.
         Trace Options Definition
         No Trace          Tracing is not activated
         Activities will not get traced.
         Regular Trace
         (Level 1)          Contains SQL, execution statistics, and execution plan.
         Provides execution path, row counts as well as produces smallest flat file.
         Trace with Binds
         (Level 4)          Regular Trace plus value supplied to SQL statement via local variables.
         Trace with Waits
         (Level 8)          Regular Trace plus database operation timings that the SQL waited to have done in order to complete, i.e. disk access.
         Trace with Binds and Waits
         (Level 12)          Regular trace with both waits and binds information.
         Contains the most complete information and will produce the largest trace file.
    ****Send me an email to [email protected],I will share the document with you.

  • Creating a directory via a jsp page sql query return

    Is it possible to create a directory based on the results of a sql query?
    i.e.
    My sql query returns application number 1234 for a building application (BC for short).
    Is it possible to create a directory /BC/1234
    It is then proposed to use an iframe to look into the directory so users can place and access scanned documents which are captured during the approval process.
    If so how?
    An example would be great.
    Jason

    Sorry hope your still around I've been away for a while. We've created a samber share to the file server where the documents are stored and mounted it within the web file directory. It works ok if there is an existing directory but if there isn't we want it to be created when the page looks for the folder. I've done this with an asp page it basically did a directory exist test first then create folder if it didn't. The problem is can't find an example of how to do the directory exist test then directory create syntax so an example of both would be great

  • SQL query with Java Server Pages

    Hey,
    I'm trying to read some information from database with SQL Query. How I can put the parameter that I get from previous *.jsp page to SQL query?
    Technologies that I use are WML, JSP and MySQL.
    I can get the parameter by method getParameter() and it is correct.
    But how to but the requested parameter into sql query and complete the sql query?
    Should I read it to some variable before putting it to sql query?
    */ this works fine */
    out.println("<p>periodi"+request.getParameter("periodi"+"loppu</p>");
    /* this doesn't work */
    ResultSet tulokset = lause.executeQuery("select * from kurssi where periodi='+request.getParameter("periodi")+'");
    /* this doesn't work */
    String periodi=request.getParameter("periodi");
    ResultSet tulokset = lause.executeQuery("select * from kurssi where periodi='periodi' '");
    Thanks,
    Rampe

    Hey,
    I'm trying to read some information from database
    se with SQL Query. How I can put the parameter that I
    get from previous *.jsp page to SQL query?
    Technologies that I use are WML, JSP and MySQL.
    I can get the parameter by method getParameter()
    () and it is correct.
    But how to but the requested parameter into sql
    ql query and complete the sql query?
    Should I read it to some variable before putting it
    it to sql query?
    */ this works fine */
    out.println("<p>periodi"+request.getParameter("periodi"
    "loppu</p>");
    /* this doesn't work */
    ResultSet tulokset = lause.executeQuery("select * from
    kurssi where
    periodi='+request.getParameter("periodi")+'");
    /* this doesn't work */
    String periodi=request.getParameter("periodi");
    ResultSet tulokset = lause.executeQuery("select *
    * from kurssi where periodi='periodi' '");
    Thanks,
    RampeTry this
    ResultSet tulokset = lause.executeQuery("select * from kurssi where periodi=" + "'" +request.getParameter("periodi")+"' " );this should work

  • Generate JSPs from SQL query

    Hello all,
    I am currently creating a web application that will allow a user to create a homepage from a template that is displayed to them. If the user is logging into the system for the first time, the template to create their homepage is displayed to them. However, if the user is logging in and has already used the template to set their homepage options, they are then forwarded to their homepage.
    The users options for their homepage are stored in a database. The problem I am having is trying to generate the jsp page ( with HTML inside also ) using SQL statements that query the table that store the users options.
    Eg. an SQL query queries the DB to see wht options the user has selected. Can anyone help me / advise me how to use these queries to generate the homepage. Thanks in advance!

    Hi aniseed,
    Thanks for a prompt reply.
    So for example can you tell me if the following sample approach is ok.
    <html>
    <head>
    <body>
    <sql:query name="query">
    SELECT * FROM SettingsTable WHERE links == "yes"
    </sql:query>
    <%-- Then to use this query result to insert selected hyperlinks that the user wants in their homepage, I would do the following ....... ? --%>
    <% if (query.size() == 0)
    <table>
    <td>
    <tr>
    </tr>
    </td>
    </table>
    %>
    Thanks again

Maybe you are looking for