String length limitation on setString() in prepared statement

Hi,
Is any body aware of the length of string that can be passed to setString() method of prepared statement. I am getting an error "Data size bigger than max size for this type" if the string length is more than 2000 chars. I am using jdk 1.2.2 for running the application.
Thanks in advance.
Nihar.

Please use the following method. It worked for me.
PreparedStatement pstmt = ......;
String str = .....;
pstmt.setObject(index,str,java.sql.Types.LONGVARCHAR);
Ranjan.

Similar Messages

  • Escape Characters - simulate the setString from Prepared Statements

    I would like to see what the value of setString() is for a given prepared statement call.
    Because of reasons that would take me to long to explain that I cannot use preparedstatements with their parameters - I need a way to execute a query like the following:
    String query = "insert into blahtable (somestring) values (\"asdfds\'\s sdsfdasfd \"\& ...\");
    PreparedStatement stmt = connection.prepareStatement(query);
    I know prepared statements can take care of this, but I want to know and write the query as above without the need of prepared statements help for string.
    Below is an example with prepared statement - but not what I want to do
    For example:
    String oddstringwithunusalcharacters = "...";
    String query = "insert into blahtable (somestring) values (?)";
    PreparedStatement stmt = connection.prepareStatement(query);
    stmt.setString(1, oddstringwithunusalcharacters);
    I would like to see what the actual query looks like and what the actual string was passed:
    --> insert into blahtable (something) values ("asdfds\'\s sdsfdasfd \"\& .... ")
    It is not sufficient enough for me to escape quotes and apostrophes because there maybe other unusual characters that I do not know of since the string is passed by an unknown source.
    Thank you in advance

    PreparedStatements actually doesn't escape quotes. It basically precompiles statements in the DB and only passes the values to the DB.
    But if you're using a plain vanilla SQL statement where you quote the string with a single quote ' then you need to escape all occurrences of exactly the same single quote ' in the actual String value. If you for example quote the string with an apostrophe ` then you just need to escape all occurrences of exactly the same apostrophe ` in the actual String value. And so on. It is nothing more than logical, is it?

  • SetString in Prepared Statement

    Help!
    I am trying to use a prepared statement and use a setString. It seems to work when I use a value as the parameter, but when I pass it a variable I get an error. Any ideas???
    THIS WORKS.....
    String buffer;
    String selectStmt1 = "SELECT veh_key_i FROM yzdbdat.mxtp010_veh " +
    "WHERE veh_chass_no = ?";
    PreparedStatement selectVehKey = connection.prepareStatement(selectStmt1);
    selectVehKey.setString(1,"2H412152");
    ResultSet getVehicle = selectVehKey.executeQuery();
    THIS DOESN'T...I GET A RIGHT TRUNCATION ERROR
    String buffer;
    String selectStmt1 = "SELECT veh_key_i FROM yzdbdat.mxtp010_veh " +
    "WHERE veh_chass_no = ?";
    PreparedStatement selectVehKey = connection.prepareStatement(selectStmt1);
    selectVehKey.setString(1,buffer);
    ResultSet getVehicle = selectVehKey.executeQuery();
    THANKS!!

    A right truncation error? I would have expected a NullPointerException, since you haven't assigned anything to that variable. But if your real code does assign something to it, then probably it is too long to fit in the database column.

  • Unable to set string in prepared statement

    Hi all,
    I just want to set an string to a prepared stmt.
    the setting string is in the format..... the integers with comma saparated....
    str="23,55,22"
    ps.setString(1,str)
    The prepare statement is taking only the first integer... i.e. 23
    can any one help me out..........
    thanks in advance,
    prakhyath

    if i am not mistaken.... If I create the Prepared
    Statement after receiving the arguments that are to
    be provided to it.... the actual purpose.. Of using
    a prepared statement is not served at all....Not creating a new Statement each time, is only one of the purposes of PreparedStatement. In this case, since the arguments should be ints (and I hope you are checking that), then it doesn't make much of a difference. But a PreparedStatement is alos used to easily facilitate the proper quoting and escaping of the parameters set, which almost eliminates any chance of an SQL injection attack. There are also a few other convienences associated with a PreparedStatement, but, in this case, you are probabyl right in that there is no advantage of PreparedStatement over Statement (as long as you are checking that the arguments provided are actually ints, otherwise you are opening yourself up to an injection attack).

  • Pass table name as parameter in prepared Statement

    Can I pass table name as parameter in prepared Statement
    for example
    select * from ? where name =?
    when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
    I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
    Thanks
    Haroon Idrees.

    haroonob wrote:
    I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
    Well, I would say (ugly as it is) String concatenation, or stored procedures.

  • Using "IN" clause in prepared statement

    I need to set string for an IN clause in a sql query. But I am not able to get the format in which the string to be set.
    TABLENAME.COLUMNAME IN ( ? )
    preparedStatement.setString( 'A' , 'B' );
    It doesn't works
    help me out?

    I need to set string for an IN clause in a sql query.
    But I am not able to get the format in which the
    string to be set.
    TABLENAME.COLUMNAME IN ( ? )
    preparedStatement.setString( 'A' , 'B' );
    It doesn't works
    help me out?You can't do that; the "?" in the SQL for a prepared statement is not used for arbitrary string replacement. Each "?" has to correspond to a data value that will be bound later.
    In other words, you can do:
    "SELECT * FROM tablename WHERE keyvalue in (?, ?, ?)";
    pstmt.setString(1,"A");
    pstmt.setString(2,"A");
    pstmt.setString(3,"A");There is no way to have a single "?" replaced by a variable-length list.

  • Prepared statement and DELETE returns 0 count

    when executing an oracle prepared statement, the count returned is allways 0 for DELETE. However, if doing an INSERT, the count returned is correct
    public void CreatePreparePurgeRcdSetArray(String sql, int i, int max, boolean create) throws SQLException,Exception
    if (create == true)
              if (preparedStatementArray == null)
                   preparedStatementArray = new PreparedStatement[max];
              int scroll_type = getScrollType();
                   if (sql.compareTo("NOT_USED") == 0)
                        preparedStatementArray[i] = null;
                   else
                        preparedStatement          = (connClass.getConn()).prepareStatement(sql);
                        preparedStatementArray[i] = preparedStatement;
                        preparedStatement          = null;
    else
         closePrepareStatementArray(max);
    public int UpdatePreparePurgeRcdSet(Vector smry, String sqlP, int i) throws SQLException,Exception
         Object[] searchs = (Object[])smry.elementAt(0);
         /*java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
         String aaa = searchs[1].toString();
         String aab = searchs[1].toString();
         java.util.Date                     dtx = sdf.parse(aaa);
         java.util.Date                     dty = sdf.parse(aab);
         oracle.sql.DATE aa1 = new DATE(new Timestamp(dtx.getTime()));
         oracle.sql.DATE aa2 = new DATE(new Timestamp(dty.getTime()));
         java.sql.Timestamp      ts1 = (java.sql.Timestamp) searchs[1] ;
         java.sql.Timestamp      ts2 = (java.sql.Timestamp) searchs[5] ;
         boolean oracle = true;
         boolean debug = true;
              if ((oracle == true) && (debug == true))
                   String sql1 = "INSERT INTO FFI_MASTER_PURGE_TBL values ('lmill', 'OSTDEVT', 'sdsadmin', ?, 30, 60, '0', 2, 'ZZZ', ' ')";
                   String sql2 = "DELETE FROM TDSADMIN.FFI_MASTER_PURGE_TBL where FORMATCATEGORY = ?";
                   String sql3 = "DELETE from TDSADMIN.SUMMARY_TBL where (ML_STI_SRC_SYS_CD = ?) AND (ML_STI_CYCLE_CD = ?) AND (ML_STI_FILE_ID = ?)";
                   preparedStatement = (connClass.getConn()).prepareStatement(sql3);
                   //preparedStatement.setString(1, "test");
                   preparedStatement.setString(1, "618");
                   preparedStatement.setString(2, "0114200601");
                   preparedStatement.setString(3, "00001591");
                   oraclePreparedStatement = (OraclePreparedStatement)preparedStatement;
                   recsDeleted = oraclePreparedStatement.executeUpdate();
              if (oracle == true)
              preparedStatement = preparedStatementArray;
              //oraclePreparedStatement.setExecuteBatch (3);
              // ML_STI_SRC_SYS_CD
              preparedStatement.setString(1, searchs[0].toString());
                   // ML_STI_SRCSYS_DTTM
              //preparedStatement.setTimestamp(2, ts1);
              //preparedStatement.setObject(2, aa1);
              // ML_STI_CYCLE_CD
              preparedStatement.setString(2, searchs[2].toString());
                   // ML_STI_FILE_ID
              preparedStatement.setString(3, searchs[3].toString());
                   // ML_STI_LOAD_DTTM
              //preparedStatement.setTimestamp(5, ts2);
              //preparedStatement.setObject(5, aa2);
         else
                   preparedStatement = preparedStatementArray[i];
              // ML_STI_SRC_SYS_CD
              preparedStatement.setString(1, searchs[0].toString());
                   // ML_STI_SRCSYS_DTTM
              preparedStatement.setTimestamp(2, ts1);
              // ML_STI_CYCLE_CD
              preparedStatement.setString(3, searchs[2].toString());
                   // ML_STI_FILE_ID
              preparedStatement.setString(4, searchs[3].toString());
                   // ML_STI_LOAD_DTTM
              preparedStatement.setTimestamp(5, ts2);
         DateClass dateClass = new DateClass();
              String startTime = dateClass.calToFormattedDateExact();
              try
                   if (oracle == true)
                        //int batch_val = oraclePreparedStatement.getExecuteBatch();
                        oraclePreparedStatement = (OraclePreparedStatement)preparedStatement;
                        recsDeleted = oraclePreparedStatement.executeUpdate();
                        //recsDeleted = oraclePreparedStatement.sendBatch();
                   else
                        recsDeleted = preparedStatement.executeUpdate();
    catch(SQLException e)
         String err = (e.getMessage()).substring(0,e.getMessage().length()-1);
         systemClass.logSqlStatement(sqlP + " : " + err, startTime);
    throw e;
    Message was edited by:
    user539085
    Message was edited by:
    user539085
    Message was edited by:
    user539085

    user539085,
    I guess it returns 0 (zero) because it doesn't delete anything. Can you verify that it did delete some records and still returned zero?
    Good Luck,
    Avi.

  • SQL Server Unicode 'N' prefix & Prepared Statements

    Hi,
    I'm using jsp, Tomcat 4.1, MSDE (SQL Server 2000 Desktop Edition), SQL Server 2000 Driver for JDBC
    to develop a simple data entry form.
    I was trying to insert a unicode string from a jsp page (input) to an SQL Server ntext field.
    My jsp includes the the definitions given below:
    <%@ page language = "java" contentType="text/html; charset=utf-8" pageEncoding="cp1254" import = "java.util.*, java.sql.*, java.text.*, java.io.*,java.lang.*" %>
    <%request.setCharacterEncoding("utf-8");%>
    <HTML>
    <HEAD>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    I executed a samlpe query INSERT INTO MyTable VALUES (N'Some Unicode String like &#351;&#350;&#304;&#305;&#287;&#286; ')
    It worked well but if the unicode string includes any apostrophe, it fails.
    So I decided to use a prepared statement.
    My code sample is as follows.
    String driver="sun.jdbc.odbc.JdbcOdbcDriver";
    Sring CURL="jdbc:odbc:portDb"; //ODBC connection
    Connection con = DriverManager.getConnection( CURL, un, pw );
    con.setAutoCommit(false);
    String sq= "INSERT INTO MyTable VALUES ?);
    String udata="Some Unicode String like &#351;&#350;&#304;&#305;&#287;&#286; ";
    PreparedStatement pstmt=con.prepareStatement(sq, ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    //Then I tried some different methods
    1) pstmt.setString(1, udata);
    //This inserts data as. "Some Unicode String like sSIigG"
    2) pstmt.setString(1, new String(udata.getBytes("utf-8"),"utf-8"));
    //This inserts data as. "Some Unicode String like sSIigG"
    byte[] bytes;
    InputStream is;
    bytes = udata.getBytes();
    is = new java.io.ByteArrayInputStream(bytes);
    3) pstmt.setUnicodeStream(1, is, bytes.length); //This inserts some strange characters
    4) pstmt.setAsciiStream(1, is, bytes.length); //This inserts some strange characters
    Reader dtxt;
    dtxt=new StringReader(udata.toString());
    5) pstmt.setCharacterStream(1, dtxt, udata.length()); //This inserts some strange characters
    pstmt.executeUpdate();
    con.commit();     
    con.close();
    Even I tried a callable statement using an sqlserver stored procedure.
    My code samples which is given above doesn't seem to insert the unicode string to the database truly.
    Is there a way to use the SQL Server National 'N' prefix in a prepared statement.
    or any suggestions to this problem.
    NOT: I can not insert especially these characters which is given below (codepage: cp1254)
    Alt+0222 Latin Capital Letter S with cedilla (&#350;)
    Alt+0254 Latin Small Letter s with cedilla (&#351;)
    Alt+0221 Latin Capital Letter I with a dot above (&#304;)
    Alt+0253 Latin Small Letter Dotless i (&#305;)
    Alt+0240 Latin Small Letter g with breve (&#287;)
    Alt+0208 Latin Capital Letter G with breve (&#286;)
    Thanks in Advance,

    I really don't know what might be happening. My suggestion (although I might get bashed for this) is to switch to another JDBC driver and see what happens.
    I'm one of the developers of the jTDS JDBC Driver. You could also try the JDBC-ODBC bridge (but as far as I know there is no way to specify Unicode/non-Unicode strings for the bridge) or a commercial driver.
    Alin.

  • Oh my God Prepared Statements are about 80 times slower than multiple inser

    I am highly suprised that in my programme a normal statement os a lot faster than a Prepared Statement. I am posting below both the Programmes, in one I am using Prepared Statements and in another I am using normal Statements. My OS is Win NT My Database is SQL Server 7. THe progamme extracts data from a file and inserts records in the database. In the test case I had A file of about 1440 records ie. 1440 inserts are made to the database, The database table is very large ie. It has around 126 Columns.
    So for inserting 1440 record froma file the Prepared Statements take around 7 Minutes . And for reading the same file and inserting the same no of records in the same database normal Statements Take only about 7 seconds. Now the JAcva docs clearly Specify that when we need to use the same stmt many times it is better to use Prepared Satements < the results that I am Getting is clear and complete violation of what java docs say.
    Below is the code with Prepared Statements
    package mps.mpsPTLF;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.util.Calendar;
    import java.util.Date;
    import gen.genCommon.genConnectionPool.*;
    import gen.genCommon.*;
    public class PTLFProcessor
         private static clsLogFile moLogFile = new clsLogFile("");
         private gen.genCommon.genConnectionPool.SharedConnectionPool mConnPool = SharedConnectionPool.getInstance(2);
         FileReader fPTLF = null;
         BufferedReader brPTLF = null;
    //**************** Begin Constructor declaration ************************
    To intialize the class variables for new Fee
         public PTLFProcessor(String pathPTLF) throws GenException
              try
                   fPTLF = new FileReader(pathPTLF);
                   brPTLF = new BufferedReader(fPTLF);
              catch (Exception e)
                   throw new GenException("Error Accessing file : " + pathPTLF + " - " + e.toString(),e );     
    //**************** End  Constructor declaration ************************
         public void PTLFGetData() throws GenException
              char pcData[];
              int HEADERSIZE = 6;
              boolean pbEndOfFile = false;
              boolean pbisFirstBlock = true;
              int piBlocksize = 0;
              int piOffset = 0;
              int piRecordsize = 0;
              String psRecordContent = "";
              Connection pConn = null;
              try
                   String psInsSql=" INSERT INTO FILE_PTLF_IN ( " +
                                       " fpi_DAT_TIM , " +
                                       " fpi_REC_TYP , " +
                                       " fpi_CRD_LN , " +
                                       " fpi_CRD_FIID , " +
                                       " fpi_CRD_NUM , " +
                                       " fpi_MBR_NUM , " +
                                       " fpi_MER_LN , " +
                                       " fpi_MER_FIID , " +
                                       " fpi_MER_GRP , " +
                                       " fpi_MER_REGN , " +
                                       " fpi_MER_ID , " +
                                       " fpi_TERM_ID , " +
                                       " fpi_SHIFT_NUM , " +
                                       " fpi_BATCH_NUM , " +
                                       " fpi_TERM_LN , " +
                                       " fpi_TERM_FIID , " +
                                       " fpi_TERM_ID_1 , " +
                                       " fpi_TRAN , " +
                                       " fpi_TERM_ID_2 , " +
                                       " fpi_REC_FRMT , " +
                                       " fpi_MER_ID_1 , " +
                                       " fpi_CLERK_ID , " +
                                       " fpi_DATA_FLAG , " +
                                       " fpi_TYP , " +
                                       " fpi_RTE_STAT , " +
                                       " fpi_ORIGINATOR , " +
                                       " fpi_RESPONDER , " +
                                       " fpi_ISS_CDE , " +
                                       " fpi_ENTRY_TIM , " +
                                       " fpi_EXIT_TIM , " +
                                       " fpi_RE_ENTRY_TIM , " +
                                       " fpi_TRAN_DAT , " +
                                       " fpi_TRAN_TIM , " +
                                       " fpi_POST_DAT , " +
                                       " fpi_ACQ_ICHG_SETL_DAT , " +
                                       " fpi_ISS_ICHG_SETL_DAT , " +
                                       " fpi_SEQ_NUM , " +
                                       " fpi_TERM_NAME_LOC , " +
                                       " fpi_TERM_OWNER_NAME , " +
                                       " fpi_TERM_CITY , " +
                                       " fpi_TERM_ST , " +
                                       " fpi_TERM_CNTRY_CDE , " +
                                       " fpi_BRCH_ID , " +
                                       " fpi_USER_FLD2 , " +
                                       " fpi_TERM_TIM_OFST , " +
                                       " fpi_ACQ_INST_ID_NUM , " +
                                       " fpi_RCV_INST_ID_NUM , " +
                                       " fpi_TERM_TYP , " +
                                       " fpi_CLERK_ID_1 , " +
                                       " fpi_GRP , " +
                                       " fpi_USER_ID , " +
                                       " fpi_RETL_SIC_CDE , " +
                                       " fpi_ORIG , " +
                                       " fpi_DEST , " +
                                       " fpi_TC , " +
                                       " fpi_T , " +
                                       " fpi_AA , " +
                                       " fpi_C , " +
                                       " fpi_CRD_TYP , " +
                                       " fpi_ACCT , " +
                                       " fpi_RESP_CDE , " +
                                       " fpi_AMT_1 , " +
                                       " fpi_AMT_2 , " +
                                       " fpi_EXP_DAT , " +
                                       " fpi_TRACK2 , " +
                                       " fpi_PIN_OFST , " +
                                       " fpi_PRE_AUTH_SEQ_NUM , " +
                                       " fpi_INVOICE_NUM , " +
                                       " fpi_ORIG_INVOICE_NUM , " +
                                       " fpi_AUTHORIZER , " +
                                       " fpi_AUTH_IND , " +
                                       " fpi_SHIFT_NUM_1 , " +
                                       " fpi_BATCH_SEQ_NUM , " +
                                       " fpi_APPRV_CDE , " +
                                       " fpi_APPRV_CDE_LGTH , " +
                                       " fpi_ICHG_RESP , " +
                                       " fpi_PSEUDO_TERM_ID , " +
                                       " fpi_RFRL_PHONE , " +
                                       " fpi_DFT_CAPTURE_FLG , " +
                                       " fpi_SETL_FLAG , " +
                                       " fpi_RVRL_CDE , " +
                                       " fpi_REA_FOR_CHRGBCK , " +
                                       " fpi_NUM_OF_CHRGBCK , " +
                                       " fpi_PT_SRV_COND_CDE , " +
                                       " fpi_PT_SRV_ENTRY_MDE , " +
                                       " fpi_AUTH_IND2 , " +
                                       " fpi_ORIG_CRNCY_CDE , " +
                                       " fpi_AUTH_CRNCY_CDE , " +
                                       " fpi_AUTH_CONV_RATE , " +
                                       " fpi_SETL_CRNCY_CDE , " +
                                       " fpi_SETL_CONV_RATE , " +
                                       " fpi_CONV_DAT_TIM , " +
                                       " fpi_IMP_IND , " +
                                       " fpi_AVAIL_BAL , " +
                                       " fpi_LEDG_BAL , " +
                                       " fpi_AMT_ON_HOLD , " +
                                       " fpi_TTL_FLOAT , " +
                                       " fpi_CUR_FLOAT , " +
                                       " fpi_ADJ_SETL_IMPACT_FLG , " +
                                       " fpi_PBF1 , " +
                                       " fpi_PBF2 , " +
                                       " fpi_PBF3 , " +
                                       " fpi_PBF4 , " +
                                       " fpi_FRWD_INST_ID_NUM , " +
                                       " fpi_CRD_ACCPT_ID_NUM , " +
                                       " fpi_CRD_ISS_ID_NUM , " +
                                       " fpi_ORIG_MSG_TYP , " +
                                       " fpi_ORIG_TRAN_TIM , " +
                                       " fpi_ORIG_TRAN_DAT , " +
                                       " fpi_ORIG_SEQ_NUM , " +
                                       " fpi_ORIG_B24_POST_DAT , " +
                                       " fpi_EXCP_RSN_CDE , " +
                                       " fpi_OVRRDE_FLG , " +
                                       " fpi_ADDR , " +
                                       " fpi_ZIP_CDE , " +
                                       " fpi_ADDR_VRFY_STAT , " +
                                       " fpi_PIN_IND , " +
                                       " fpi_PIN_TRIES , " +
                                       " fpi_PRE_AUTH_TS_DAT , " +
                                       " fpi_PRE_AUTH_TS_TIM , " +
                                       " fpi_PRE_AUTH_HLDS_LVL , " +
                                       " fpi_USER_FLD5 , " +
                                       " fpi_LEN , " +
                                       " fpi_INFO )" +
                                       " VALUES ( " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                   pConn = mConnPool.getConnection();
                   PreparedStatement pStmt = pConn.prepareStatement(psInsSql);
                   while (!pbEndOfFile)
                        pcData = new char [HEADERSIZE];                    // Reading each Block Header
                        brPTLF.read (pcData, 0, HEADERSIZE);
                        piBlocksize = Integer.parseInt (new String (pcData));
                        piOffset = HEADERSIZE;
                        while (piOffset < piBlocksize)
                        {                      // Read the records upto end of block
                             pcData = new char [HEADERSIZE];               // Reading each Record Header
                             brPTLF.read (pcData, 0, HEADERSIZE);
                             piRecordsize = Integer.parseInt (new String (pcData));
                             piOffset += HEADERSIZE;
                             pcData = new char [piRecordsize - HEADERSIZE];     // Reading each Record Content
                             brPTLF.read (pcData, 0, piRecordsize - HEADERSIZE);
                             psRecordContent = new String (pcData);
                             piOffset += piRecordsize - HEADERSIZE;
                             moLogFile.writeToLog(psRecordContent);
                             if (pbisFirstBlock)
                                  if (!psRecordContent.startsWith ("TH"))
                                       throw new GenException ("Invalid File Format, missing 'TH'");
                                  pcData = new char [HEADERSIZE];          // Reading next Record Header
                                  brPTLF.read (pcData, 0, HEADERSIZE);
                                  piRecordsize = Integer.parseInt (new String (pcData));
                                  piOffset += HEADERSIZE;
                                  pcData = new char [piRecordsize - HEADERSIZE];// Reading next Record Content (Must be FH)
                                  brPTLF.read (pcData, 0, piRecordsize - HEADERSIZE);
                                  psRecordContent = new String (pcData);
                                  piOffset += piRecordsize - HEADERSIZE;
                                  if (!psRecordContent.startsWith ("FH"))
                                       throw new GenException ("File Header Not Found");
                                  pbisFirstBlock = false;
                             else if (psRecordContent.startsWith ("DR"))
                                  psRecordContent = psRecordContent.substring(2);
                        /*          if (psRecordContent.length() != 1820 ) // && psRecordContent.length() != 846)
                                       // insert in error table
                                       continue;
                                  if ( psRecordContent.substring(453-1, 455).equals ("000") || psRecordContent.substring(453-1, 455).equals ("001") )
                                       pStmt.setString (1, psRecordContent.substring(1-1,19));
                                       pStmt.setString (2, psRecordContent.substring(20-1,21));
                                       pStmt.setString (3, psRecordContent.substring(22-1,25));
                                       pStmt.setString (4, psRecordContent.substring(26-1,29));
                                       pStmt.setString (5, psRecordContent.substring(30-1,48));
                                       pStmt.setString (6, psRecordContent.substring(49-1,51));
                                       pStmt.setString (7, psRecordContent.substring(52-1,55));
                                       pStmt.setString (8, psRecordContent.substring(56-1,59));
                                       pStmt.setString (9, psRecordContent.substring(60-1,63));
                                       pStmt.setString (10, psRecordContent.substring(64-1,67));
                                       pStmt.setString (11, psRecordContent.substring(68-1,86));
                                       pStmt.setString (12, psRecordContent.substring(87-1,102));
                                       pStmt.setString (13, psRecordContent.substring(103-1,105));
                                       pStmt.setString (14, psRecordContent.substring(106-1,108));
                                       pStmt.setString (15, psRecordContent.substring(109-1,112));
                                       pStmt.setString (16, psRecordContent.substring(113-1,116));
                                       pStmt.setString (17, psRecordContent.substring(117-1,132));
                                       pStmt.setString (18, psRecordContent.substring(133-1,140));
                                       pStmt.setString (19, psRecordContent.substring(141-1,156));
                                       pStmt.setString (20, psRecordContent.substring(157-1,157));
                                       pStmt.setString (21, psRecordContent.substring(158-1,176));
                                       pStmt.setString (22, psRecordContent.substring(177-1,182));
                                       pStmt.setString (23, psRecordContent.substring(183-1,183));
                                       pStmt.setString (24, psRecordContent.substring(184-1,187));
                                       pStmt.setString (25, psRecordContent.substring(188-1,189));
                                       pStmt.setString (26, psRecordContent.substring(190-1,190));
                                       pStmt.setString (27, psRecordContent.substring(191-1,191));
                                       pStmt.setString (28, psRecordContent.substring(192-1,193));
                                       pStmt.setString (29, psRecordContent.substring(194-1,212));
                                       pStmt.setString (30, psRecordContent.substring(213-1,231));
                                       pStmt.setString (31, psRecordContent.substring(232-1,250));
                                       pStmt.setString (32, psRecordContent.substring(251-1,256));
                                       pStmt.setString (33, psRecordContent.substring(257-1,264));
                                       pStmt.setString (34, psRecordContent.substring(265-1,270));
                                       pStmt.setString (35, psRecordContent.substring(271-1,276));
                                       pStmt.setString (36, psRecordContent.substring(277-1,282));
                                       pStmt.setString (37, psRecordContent.substring(283-1,294));
                                       pStmt.setString (38, psRecordContent.substring(295-1,319));
                                       pStmt.setString (39, psRecordContent.substring(320-1,341));
                                       pStmt.setString (40, psRecordContent.substring(342-1,354));
                                       pStmt.setString (41, psRecordContent.substring(355-1,357));
                                       pStmt.setString (42, psRecordContent.substring(358-1,359));
                                       pStmt.setString (43, psRecordContent.substring(360-1,363));
                                       pStmt.setString (44, psRecordContent.substring(364-1,366));
                                       pStmt.setString (45, psRecordContent.substring(367-1,371));
                                       pStmt.setString (46, psRecordContent.substring(372-1,382));
                                       pStmt.setString (47, psRecordContent.substring(383-1,393));
                                       pStmt.setString (48, psRecordContent.substring(394-1,395));
                                       pStmt.setString (49, psRecordContent.substring(396-1,401));
                                       pStmt.setString (50, psRecordContent.substring(402-1,405));
                                       pStmt.setString (51, psRecordContent.substring(406-1,413));
                                       pStmt.setString (52, psRecordContent.substring(414-1,417));
                                       pStmt.setString (53, psRecordContent.substring(418-1,421));
                                       pStmt.setString (54, psRecordContent.substring(422-1,425));
                                       pStmt.setString (55, psRecordContent.substring(426-1,427));
                                       pStmt.setString (56, psRecordContent.substring(428-1,428));
                                       pStmt.setString (57, psRecordContent.substring(429-1,430));
                                       pStmt.setString (58, psRecordContent.substring(431-1,431));
                                       pStmt.setString (59, psRecordContent.substring(432-1,433));
                                       pStmt.setString (60, psRecordContent.substring(434-1,452));
                                       pStmt.setString (61, psRecordContent.substring(453-1,455));
                                       pStmt.setString (62, psRecordContent.substring(456-1,474));
                                       pStmt.setString (63, psRecordContent.substring(475-1,493));
                                       pStmt.setString (64, psRecordContent.substring(494-1,497));
                                       pStmt.setString (65, psRecordContent.substring(498-1,537));
                                       pStmt.setString (66, psRecordContent.substring(538-1,553));
                                       pStmt.setString (67, psRecordContent.substring(554-1,565));
                                       pStmt.setString (68, psRecordContent.substring(566-1,575));
                                       pStmt.setString (69, psRecordContent.substring(576-1,585));
                                       pStmt.setString (70, psRecordContent.substring(586-1,601));
                                       pStmt.setString (71, psRecordContent.substring(602-1,602));
                                       pStmt.setString (72, psRecordContent.substring(603-1,605));
                                       pStmt.setString (73, psRecordContent.substring(606-1,608));
                                       pStmt.setString (74, psRecordContent.substring(609-1,616));
                                       pStmt.setString (75, psRecordContent.substring(617-1,617));
                                       pStmt.setString (76, psRecordContent.substring(618-1,625));
                                       pStmt.setString (77, psRecordContent.substring(626-1,629));
                                       pStmt.setString (78, psRecordContent.substring(630-1,649));
                                       pStmt.setString (79, psRecordContent.substring(650-1,650));
                                       pStmt.setString (80, psRecordContent.substring(651-1,651));
                                       pStmt.setString (81, psRecordContent.substring(652-1,653));
                                       pStmt.setString (82, psRecordContent.substring(654-1,655));
                                       pStmt.setString (83, psRecordContent.substring(656-1,656));
                                       pStmt.setString (84, psRecordContent.substring(657-1,658));
                                       pStmt.setString (85, psRecordContent.substring(659-1,661));
                                       pStmt.setString (86, psRecordContent.substring(662-1,662));
                                       pStmt.setString (87, psRecordContent.substring(663-1,665));
                                       pStmt.setString (88, psRecordContent.substring(666-1,668));
                                       pStmt.setString (89, psRecordContent.substring(669-1,676));
                                       pStmt.setString (90, psRecordContent.substring(677-1,679));
                                       pStmt.setString (91, psRecordContent.substring(680-1,687));
                                       pStmt.setString (92, psRecordContent.substring(688-1,706));
                                       pStmt.setString (93, psRecordContent.substring(707-1,707));
                                       pStmt.setString (94, psRecordContent.substring(708-1,708));
                                       pStmt.setString (95, psRecordContent.substring(709-1,709));
                                       pStmt.setString (96, psRecordContent.substring(710-1,710));
                                       pStmt.setString (97, psRecordContent.substring(711-1,711));
                                       pStmt.setString (98, psRecordContent.substring(712-1,712));
                                       pStmt.setString (99, psRecordContent.substring(713-1,713));
                                       pStmt.setString (100, psRecordContent.substring(714-1,714));
                                       pStmt.setString (101, psRecordContent.substring(715-1,715));
                                       pStmt.setString (102, psRecordContent.substring(716-1,716));
                                       pStmt.setString (103, psRecordContent.substring(717-1,717));
                                       pStmt.setString (104, psRecordContent.substring(718-1,728));
                                       pStmt.setString (105, psRecordContent.substring(729-1,739));
                                       pStmt.setString (106, psRecordContent.substring(740-1,750));
                                       pStmt.setString (107, psRecordContent.substring(751-1,754));
                                       pStmt.setString (108, psRecordContent.substring(755-1,762));
                                       pStmt.setString (109, psRecordContent.substring(763-1,766));
                                       pStmt.setString (110, psRecordContent.substring(767-1,778));
                                       pStmt.setString (111, psRecordContent.substring(779-1,782));
                                       pStmt.setString (112, psRecordContent.substring(783-1,785));
                                       pStmt.setString (113, psRecordContent.substring(786-1,786));
                                       pStmt.setString (114, psRecordContent.substring(787-1,806));
                                       pStmt.setString (115, psRecordContent.substring(807-1,815));
                                       pStmt.setString (116, psRecordContent.substring(816-1,816));
                                       pStmt.setString (117, psRecordContent.substring(817-1,817));
                                       pStmt.setString (118, psRecordContent.substring(818-1,818));
                                       pStmt.setString (119, psRecordContent.substring(819-1,824));
                                       pStmt.setString (120, psRecordContent.substring(825-1,832));
                                       pStmt.setString (121, psRecordContent.substring(833-1,833));
                                       pStmt.setString (122, psRecordContent.substring(834-1,866));
                                       pStmt.setString (123, psRecordContent.substring(867-1,870));
                                       pStmt.setString (124, psRecordContent.substring(871-1,1070));
                                       if (pStmt.executeUpdate() != 1)
                                            throw new GenException ("Insertion failed");
                                            String psMsgType = psRecordContent.substring (184-1, 187);
                                            if (true)//updateTable (conn, pstmt, pstmt1, pstmt2, psRecordContent, out, bw))
                                                 if (psMsgType.equals ("0500") || psMsgType.equals ("0520"))
                                                           //piSettlementDR++;
                                                 if (psMsgType.equals ("0210"))
                                                           //piUpdatedDR++;
                                                 if (psMsgType.equals ("0220") || psMsgType.equals ("0320") || psMsgType.equals ("0420"))
                                                      //reversalDR++;
                                                 //validDR++;
                                  //totalDR++;
                             else if (psRecordContent.startsWith ("FT"))
                                  pcData = new char [HEADERSIZE];     // Reading next Record Header
                                  brPTLF.read (pcData, 0, HEADERSIZE);
                                  piRecordsize = Integer.parseInt (new String (pcData));
                                  piOffset += HEADERSIZE;
                                  pcData = new char [piRecordsize - HEADERSIZE];// Reading next Record Content (Must be TT)
                                  brPTLF.read (pcData, 0, piRecordsize - HEADERSIZE);
                                  psRecordContent = new String (pcData);
                                  piOffset += piRecordsize - HEADERSIZE;
                                  if (!psRecordContent.startsWith ("TT"))
                                       throw new GenException ("Total Trailer not Found.");
                                  pbEndOfFile = true;
                        } // while (piOffset < piBlocksize)
                   } // while (!pbEndOfFile)
                   brPTLF.close();
                   fPTLF.close();
                   pStmt.close();
              catch (Exception e)
                   moLogFile.printStackTrace(e);
              finally
                   mConnPool.free(pConn);
         public static void main(String args[])
              try
                   PTLFProcessor test=new PTLFProcessor("c:\\test.txt");
                   test.PTLFGetData();
              catch (Exception e)
                   clsLogFile.printStackTrace(e);
    }Now is the code with normal Statements
    //package mps.mpsPTLF;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.util.Calendar;
    import java.util.Date;
    import gen.genCommon.genConnectionPool.*;
    import gen.genCommon.*;
    public class PTLFProcessor1
         private static clsLogFile moLogFile = new clsLogFile("");
         private gen.genCommon.genConnectionPool.SharedConnectionPool mConnPool = SharedConnectionPool.getInstance(2);
         FileReader fPTLF = null;
         BufferedReader brPTLF = null;
    //**************** Begin Constructor declaration ************************
    To intialize the class variables for new Fee
         public PTLFProcessor1(String pathPTLF) throws GenException
              try
                   fPTLF = new FileReader(pathPTLF);
                   brPTLF = new BufferedReader(fPTLF);
              catch (Exception e)
                   throw new GenException("Error Accessing file : " + pathPTLF + " - " + e.toString(),e );     
    //**************** End  Constructor declaration ************************
         public void PTLFGetData() throws GenException
              char pcData[];
              int HEADERSIZE = 6;
              boolean pbEndOfFile = false;
              boolean pbisFirstBlock = true;
              int piBlocksize = 0;
              int piOffset = 0;
              int piRecordsize = 0;
              String psRecordContent = "";
              Connection pConn = null;
              int cnt=0;
              try
                   String psInsSql=" INSERT INTO FILE_PTLF_IN ( " +
                                       " fpi_DAT_TIM , " +
                                       " fpi_REC_TYP , " +
                                       " fpi_CRD_LN , " +
                                       " fpi_CRD_FIID , " +
                                       " fpi_CRD_NUM , " +
                                       " fpi_MBR_NUM , " +
                                       " fpi_MER_LN , " +
                                       " fpi_MER_FIID , " +
                                       " fpi_MER_GRP , " +
                                       " fpi_MER_REGN , " +
                                       " fpi_MER_ID , " +
                                       " fpi_TERM_ID , " +
                                       " fpi_SHIFT_NUM , " +
                                       " fpi_BATCH_NUM , " +
                                       " fpi_TERM_LN , " +
                                       " fpi_TERM_FIID , " +
                                       " fpi_TERM_ID_1 , " +
                                       " fpi_TRAN , " +
                                       " fpi_TERM_ID_2 , " +
                                       " fpi_REC_FRMT , " +
                                       " fpi_MER_ID_1 , " +
                                       " fpi_CLERK_ID , " +
                                       " fpi_DATA_FLAG , " +
                                       " fpi_TYP , " +
                                       " fpi_RTE_STAT , " +
                                       " fpi_ORIGINATOR , " +
                                       " fpi_RESPONDER , " +
                                       " fpi_ISS_CDE , " +
                                       " fpi_ENTRY_TIM , " +
                                       " fpi_EXIT_TIM , " +
                                       " fpi_RE_ENTRY_TIM , " +
                                       " fpi_TRAN_DAT , " +
                                       " fpi_TRAN_TIM , " +
                                       " fpi_POST_DAT , " +
                                       " fpi_ACQ_ICHG_SETL_DAT , " +
                                       " fpi_ISS_ICHG_SETL_DAT , " +
                                       " fpi_SEQ_NUM , " +
                                       " fpi_TERM_NAME_LOC , " +
                                       " fpi_TERM_OWNER_NAME , " +
                                       " fpi_TERM_CITY , " +
                                       " fpi_TERM_ST , " +
                                       " fpi_TERM_CNTRY_CDE , " +
                                       " fpi_BRCH_ID , " +
                                       " fpi_USER_FLD2 , " +
                                       " fpi_TERM_TIM_OFST , " +
                                       " fpi_ACQ_INST_ID_NUM , " +
                                       " fpi_RCV_INST_ID_NUM , " +
                                       " fpi_TERM_TYP , " +
                                       " fpi_CLERK_ID_1 , " +
                                       " fpi_GRP , " +
                                       " fpi_USER_ID , " +
                                       " fpi_RETL_SIC_CDE , " +
                                       " fpi_ORIG , " +
                                       " fpi_DEST , " +
                                       " fpi_TC , " +
                                       " fpi_T , " +
                                       " fpi_AA , " +
                                       " fpi_C , " +
                                       " fpi_CRD_TYP , " +
                                       " fpi_ACCT , " +
                                       " fpi_RESP_CDE , " +
                                       " fpi_AMT_1 , " +
                                       " fpi_AMT_2 , " +
                                       " fpi_EXP_DAT , " +
                                       " fpi_TRACK2 , " +
                                       " fpi_PIN_OFST , " +
                                       " fpi_PRE_AUTH_SEQ_NUM , " +
                                       " fpi_INVOICE_NUM , " +
                                       " fpi_ORIG_INVOICE_NUM , " +
                                       " fpi_AUTHORIZER , " +
                                       " fpi_AUTH_IND , " +
                                       " fpi_SHIFT_NUM_1 , " +
                                       " fpi_BATCH_SEQ_NUM , " +
                                       " fpi_APPRV_CDE , " +
                                       " fpi_APPRV_CDE_LGTH , " +
                                       " fpi_ICHG_RESP , " +
                                       " fpi_PSEUDO_TERM_ID , " +
                                       " fpi_RFRL_PHONE , " +
                                       " fpi_DFT_CAPTURE_FLG , " +
                                       " fpi_SETL_FLAG , " +
                                       " fpi_RVRL_CDE , " +
                                       " fpi_REA_FOR_CHRGBCK , " +
                                       " fpi_NUM_OF_CHRGBCK , " +
                                       " fpi_PT_SRV_COND_CDE , " +
                                       " fpi_PT_SRV_ENTRY_MDE , " +
                                       " fpi_AUTH_IND2 , " +
                                       " fpi_ORIG_CRNCY_CDE , " +
                                       " fpi_AUTH_CRNCY_CDE , " +
                                       " fpi_AUTH_CONV_RATE , " +
                                       " fpi_SETL_CRNCY_CDE , " +
                                       " fpi_SETL_CONV_RATE , " +
                                       " fpi_CONV_DAT_TIM , " +
                                       " fpi_IMP_IND , " +
                                       " fpi_AVAIL_BAL , " +
                                       " fpi_LEDG_BAL , " +
                                       " fpi_AMT_ON_HOLD , " +
                                       " fpi_TTL_FLOAT , " +
                                       " fpi_CUR_FLOAT , " +
                                       " fpi_ADJ_SETL_IMPACT_FLG , " +
                                       " fpi_PBF1 , " +
                                       " fpi_PBF2 , " +
                                       " fpi_PBF3 , " +
                                       " fpi_PBF4 , " +
                                       " fpi_FRWD_INST_ID_NUM , " +
                                       " fpi_CRD_ACCPT_ID_NUM , " +
                                       " fpi_CRD_ISS_ID_NUM , " +
                                       " fpi_ORIG_MSG_TYP , " +
                                       " fpi_ORIG_TRAN_TIM , " +
                                       " fpi_ORIG_TRAN_DAT , " +
                                       " fpi_ORIG_SEQ_NUM , " +
                                       " fpi_ORIG_B24_POST_DAT , " +
                                       " fpi_EXCP_RSN_CDE , " +
                                       " fpi_OVRRDE_FLG , " +
                                       " fpi_ADDR , " +
                                       " fpi_ZIP_CDE , " +
                                       " fpi_ADDR_VRFY_STAT , " +
                                       " fpi_PIN_IND , " +
                                       " fpi_PIN_TRIES , " +
                                       " fpi_PRE_AUTH_TS_DAT , " +
                                       " fpi_PRE_AUTH_TS_TIM , " +
                                       " fpi_PRE_AUTH_HLDS_LVL , " +
                                       " fpi_USER_FLD5 , " +
                                       " fpi_LEN , " +
                                       " fpi_INFO )" +
                                       " VALUES ";
                                       ( " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                                       " ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, " +
                   pConn = mConnPool.getConnection();
                   Statement Stmt=pConn.createStatement();
                   while (!pbEndOfFile)
                        pcData = new char [HEADERSIZE];                    // Reading each Block Header
                        brPTLF.read (pcData, 0, HEADERSIZE);
                        piBlocksize = Integer.parseInt (new String (pcData));
                        piOffset = HEADERSIZE;
                        while (piOffset < piBlocksize)
                        {                      // Read the records upto end of block
                             pcData = new char [HEADERSIZE];               // Reading each Record Header
                             brPTLF.read (pcData, 0, HEADERSIZE);
                             piRecordsize = Integer.parseInt (new String (pcData));
                             piOffset += HEADERSIZE;
                             pcData = new char [piRecordsize - HEADERSIZE];     // Reading each Record Content
                             brPTLF.read (pcData, 0, piRecordsize - HEADERSIZE);
                             psRecordContent = new String (pcData);
                             piOffset += piRecordsize - HEADERSIZE;
                             if (pbisFirstBlock)
                                  if (!psRecordContent.startsWith ("TH"))
                                       throw new GenException ("Invalid File Format, missing 'TH'");
                                  pcData = new char [HEADERSIZE];          // Reading next Record Header
                                  brPTLF.read (pcData, 0, HEADERSIZE);
                                  piRecordsize = Integer.parseInt (new String (pcData));
                                  piOffset += HEADERSIZE;
                                  pcData = new char [piRecordsize - HEADERSIZE];// Reading next Record Content (Must be FH)
                                  brPTLF.read (pcData, 0, piRecordsize - HEADERSIZE);
                                  psRecordContent = new String (pcData);
                                  piOffset += piRecordsize - HEADERSIZE;
                                  if (!psRecordContent.startsWith ("FH"))
                                       throw new GenException ("File Header Not Found");
                                  pbisFirstBlock = false;
                             else if (psRecordContent.startsWith ("DR"))
                                  psRecordContent = psRecordContent.substring(2);
                        /*          if (psRecordContent.length() != 1820 ) // && psRecordContent.length() != 846)
                                       // insert in error table
                                       continue;
                                  String psValues = null;
                                  if ( psRecordContent.substring(453-1, 455).equals ("000") || psRecordContent.substring(453-1, 455).equals ("001") )
                                       psValues = "('" +  psRecordContent.substring(1-1,19) + "','" +
                                                        psRecordContent.substring(20-1,21) + "','" +
                                                       psRecordContent.substring(22-1,25) + "','" +
                                                       psRecordContent.substring(26-1,29) + "','" +
                                                       psRecordContent.substring(30-1,48) + "','" +
                                                       psRecordContent.substring(49-1,51) + "','" +
                                                       psRecordContent.substring(52-1,55) + "','" +
                                                       psRecordContent.substring(56-1,59) + "','" +
                                                       psRecordContent.substring(60-1,63) + "','" +
                                                       psRecordContent.substring(64-1,67) + "','" +
                                                       psRecordContent.substring(68-1,86) + "','" +
                                                       psRecordContent.substring(87-1,102) + "','" +
                                                       psRecordContent.substring(103-1,105) + "','" +
                                                       psRecordContent.substring(106-1,108) + "','" +
                                                       psRecordContent.substring(109-1,112) + "','" +
                                                       psRecordContent.substring(113-1,116) + "','" +
                                                       psRecordContent.substring(117-1,132) + "','" +
                                                       psRecordContent.substring(133-1,140) + "','" +
                                                       psRecordContent.substring(141-1,156) + "','" +
                                                       psRecordContent.substring(157-1,157) + "','" +
                                                       psRecordContent.substring(158-1,176) + "','" +
                                                       psRecordContent.substring(177-1,182) + "','" +
                                                       psRecordContent.substring(183-1,183) + "','" +
                                                       psRecordContent.substring(184-1,187) + "','" +
                                                       psRecordContent.substring(188-1,189) + "','" +
                                                       psRecordContent.substring(190-1,190) + "','" +
                                                       psRecordContent.substring(191-1,191) + "','" +
                                                       psRecordContent.substring(192-1,193) + "','" +
                                                       psRecordContent.substring(194-1,212) + "','" +
                                                       psRecordContent.substring(213-1,231) + "','" +
                                                       psRecordContent.substring(232-1,250) + "','" +
                                                       psRecordContent.substring(251-1,256) + "','" +
                                                       psRecordContent.substring(257-1,264) + "','" +
                                                       psRecordContent.substring(265-1,270) + "','" +
                                                       psRecordContent.substring(271-1,276) + "','" +
                                                       psRecordContent.substring(277-1,282) + "','" +
                                                       psRecordContent.substring(283-1,294) + "','" +
                                                       psRecordContent.substring(295-1,319) + "','" +
                                                       psRecordContent.substring(320-1,341) + "','" +
                                                       psRecordContent.substring(342-1,354) + "','" +
                                                       psRecordContent.substring(355-1,357) + "','" +
                                                       psRecordContent.substring(358-1,359) + "','" +
                                                       psRecordContent.substring(360-1,363) + "','" +
       

    You posted this question in several other forums. Please don't do that.

  • Use of Prepared Statement in adf

    Hi Experts,
    I am confused with the Use of prepared statement in adf.
    My use case is ,
    I have to update a table from every page in my application under certain conditions.
    My question is ,
    whether I have to create the VO iterator binding in every page and by calling the createinsert and insert the data in to the table or
    use a common method in the Application module impl
    which is using a prepared statement,(which is not even creating the ViewObject ) like
    PreparedStatement st = null;
    String sql = "INSERT INTO hr.departments (DEPARTMENT_ID,    DEPARTMENT_NAME,   MANAGER_ID,   LOCATION_ID) VALUES (seq,?,?,?)";
                st=getDBTransaction().createPreparedStatement(sql,0);
                st.setString(1, name);
                st.setString(2, mgr_id);
                st.setString(3, Loc_id);
                st.execute();
    getDBTransaction().commit();which is the best approach?
    Studio Edition Version 11.1.1.2.0
    Ranjith

    Ranjith,
    Without further understanding the use case, there's not really much difference between the two approaches. In both cases, you'd have a binding in the page definition (either an iterator binding for the VO or a method binding for the AM service method). Both will use bind variables. The main difference I can see is that, depending on how you have configured your AM pooling settings, the VO method will incur fewer parses in the DB because the AM will cache prepared statements for you.
    John

  • Limitation on SQL executing select statement from ADO and Oracle 8.1.7.1 OleDB Driver

    Hi,
    we are running a query with a big dunamic select statement from VB code using ADO command object. When Execute method is called system hangs and control won't return back to the application. it seems to be that there is some type limitation on Query string length. Please tell us if there is any?
    we are running Oracle 8.1.7 Server on Windows 200 Server and connecting from a W2K professional, ADO 2.6 and Oracle OLEDB 8.1.7.1 OLEDB Driver.
    Sample code:
    Dim rs As ADODB.Recordset
    Dim cmd As ADODB.Command
    Set cmd = New Command
    With cmd
    .CommandText = ' some text with more than 2500 characters
    .CommandType = adCmdText
    Set rs = .Execute
    End With
    when i debug using VB6 and when .Execute line is called system hangs or return a message method <<somemethod> of <<some class name>> failed error.
    Any help is appreciated.
    Thanks,
    Anil

    A stored procedure would only slow you down here if it was poorly written. I suspect you want to use the translate function. I'm cutting & pasting examples from the documentation-- a search at tahiti.oracle.com will give you all the info you'll need.
    Examples
    The following statement translates a license number. All letters 'ABC...Z' are translated to 'X' and all digits '012 . . . 9' are translated to '9':
    SELECT TRANSLATE('2KRW229',
    '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    '9999999999XXXXXXXXXXXXXXXXXXXXXXXXXX') "License"
    FROM DUAL;
    License
    9XXX999
    The following statement returns a license number with the characters removed and the digits remaining:
    SELECT TRANSLATE('2KRW229',
    '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')
    "Translate example"
    FROM DUAL;
    Translate example
    2229
    Also, LIKE '%<string>%' is going to be rather expensive simply because it has to compare the entire string and because it forces full table scans, rather than using indexes. You could speed this sort of query up by using interMedia Text (Oracle Text now in 9i). If you can eliminate one of the '%' options, you could also improve things.
    My guess is that your stored procedure is inefficient and that's causing the problem-- 5k rows per table should be pretty trivial.
    If you post your query over on the PL/SQL forum, there are better performance tuners than I that might have more hints for you. To get really good advice, though, you'lllikely have to get at least the execution plan for this statement and may need to do some profiling to identify the problem areas.
    Justin

  • Problem in prepared Statement

    hi,
    i have used following prepared Statement for the update in database.
    Can any one tell me that,How can i use date in following method.
    I have 4 field for date as given below:(BOLD shown)
    I have used String in that place.
    It is not working.
    PreparedStatement pstatement = conn.prepareStatement(
    "UPDATE sec_mast SET catg_code=?, vou_no=?, vou_date=?, vou_amt=?, due_date1=?, due_date2=?, mat_date=? where sec_no=? ");
    pstatement.setInt(1,Integer.parseInt(request.getParameter("catg_code")));
    pstatement.setString(2,request.getParameter("vou_no"));
    pstatement.setString(3,request.getParameter("vou_date"));
    pstatement.setInt(4,Integer.parseInt(request.getParameter("vou_amt")));
    pstatement.setString(5,request.getParameter("due_date1"));
    pstatement.setString(6,request.getParameter("due_date2"));
    pstatement.setString(7,request.getParameter("mat_date"));
    pstatement.setInt(8,Integer.parseInt(request.getParameter("sec_no")));
    int rowCount = pstatement.executeUpdate();
    conn.setAutoCommit(false);
    conn.setAutoCommit(true);
    plz help me

    thanx for u r reply.
    MY whole code is shown as below:
    This page is for the updating the values in database..
    <html>
    <body>
    <table>
    <tr>
    <td>
    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page language="java" import="java.sql.*" %>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:pf","scott","ttlscott");
    System.out.println("got connection");
    %>
    <%
    String action = request.getParameter("action");
    // Check if an update is requested
    if (action != null && action.equals("update")) {
    conn.setAutoCommit(false);
    PreparedStatement pstatement = conn.prepareStatement(
    "UPDATE sec_mast SET sec_no=? , catg_code=?, face_val=?, pur_val=?, int_paid=?, int_recd=?, brkr=?, vou_no=?, vou_date=?, vou_amt=?, due_date1=?, due_date2=?, lf_no=?, mat_date=? where tot_val=? ");
    pstatement.setInt(1,Integer.parseInt(request.getParameter("sec_no")));
    pstatement.setInt(2,Integer.parseInt(request.getParameter("catg_code")));
    pstatement.setInt(3,Integer.parseInt(request.getParameter("face_val")));
    pstatement.setInt(4,Integer.parseInt(request.getParameter("pur_val")));
    pstatement.setInt(5,Integer.parseInt(request.getParameter("int_paid")));
    pstatement.setInt(6,Integer.parseInt(request.getParameter("int_recd")));
    pstatement.setInt(7,Integer.parseInt(request.getParameter("brkr")));
    pstatement.setString(8,request.getParameter("vou_no"));
    pstatement.setString(9,request.getParameter("vou_date"));
    pstatement.setInt(10,Integer.parseInt(request.getParameter("vou_amt")));
    pstatement.setString(11,request.getParameter("due_date1"));
    pstatement.setString(12,request.getParameter("due_date2"));
    pstatement.setString(13,request.getParameter("lf_no"));
    pstatement.setString(14,request.getParameter("mat_date"));
    pstatement.setInt(15,Integer.parseInt(request.getParameter("tot_val")));
    int rowCount = pstatement.executeUpdate();
    conn.setAutoCommit(false);
    conn.setAutoCommit(true);
    %>
    <%
    // Create the statement
    Statement statement = conn.createStatement();
    ResultSet rs = statement.executeQuery
    ("SELECT * from sec_mast ");
    %>
    <%
    // Iterate over the ResultSet
    while ( rs.next() ) {
    %>
    <tr>
    <form action="security_update.jsp" method="get">
    <input type="hidden" value="update" name="action">
    <td><input value="<%= rs.getInt("sec_no") %>" name="sec_no"></td>
    <td><input value="<%= rs.getInt("catg_code") %>" name="catg_code"></td>
    <td><input value="<%= rs.getInt("face_val") %>" name="face_val"></td>
    <td><input value="<%= rs.getInt("pur_val") %>" name="pur_val"></td>
    <td><input value="<%= rs.getInt("int_paid") %>" name="int_paid"></td>
    <td><input value="<%= rs.getInt("int_recd") %>" name="int_recd"></td>
    <td><input value="<%= rs.getInt("brkr") %>" name="brkr"></td>
    <td><input value="<%= rs.getInt("tot_val") %>" name="tot_val"></td>
    <td><input value="<%= rs.getString("vou_no") %>" name="vou_no"></td>
    <td><input value="<%= rs.getDate("vou_date") %>" name="vou_date"></td>
    <td><input value="<%= rs.getInt("vou_amt") %>" name="vou_amt"></td>
    <td><input value="<%= rs.getDate("due_date1") %>" name="due_date1"></td>
    <td><input value="<%= rs.getDate("due_date2") %>" name="due_date2"></td>
    <td><input value="<%= rs.getString("lf_no") %>" name="lf_no"></td>
    <td><input value="<%= rs.getDate("mat_date") %>" name="mat_date"></td>
    <td><input type="submit" value="Update"></td>
    </form>
    </tr>
    <%
    %>
    </table>
    <%
    // Close the ResultSet
    rs.close();
    // Close the Statement
    statement.close();
    // Close the Connection
    conn.close();
    } catch (SQLException sqle) {
    out.println(sqle.getMessage());
    } catch (Exception e) {
    out.println(e.getMessage());
    %>
    </td>
    </tr>
    </body>
    </html>

  • Application is in 'Prepared' state instead of 'Active' state.

    I m using below code to deploy an application on weblogic 11g
    import java.io.*;
    import java.util.Hashtable;
    import weblogic.deploy.api.tools.*;  //SesionHelper
    import weblogic.deploy.api.spi .*;  //WebLogicDeploymentManager
    import javax.enterprise.deploy.spi.TargetModuleID;
    import javax.enterprise.deploy.spi.status.ProgressObject;
    import javax.enterprise.deploy.spi.status.DeploymentStatus;
    import javax.enterprise.deploy.shared.ModuleType;
    import javax.enterprise.deploy.spi.Target;
    import javax.management.MBeanServerConnection;
    import javax.management.remote.JMXConnector;
    import javax.management.remote.JMXConnectorFactory;
    import javax.management.remote.JMXServiceURL;
    import javax.naming.Context;
    public class WeblogicTest
         public static void main(String ar[]) throws Exception
              System.out.println("Start Deploying");
              WebLogicDeploymentManager deployManager=SessionHelper.getRemoteDeploymentManager( "t3", "10.0.0.47", "7003", "weblogic",
              "weblogic123");
              System.out.println("Deploy Manager  :  " + deployManager);
              DeploymentOptions options = new DeploymentOptions();
              options.setName("TC33");          //TODO
              Target targets[] = deployManager.getTargets();
              System.out.println("Target  :  " + targets);
              Target deployTargets[]=new Target[1];     
              int temp=0;
              for (temp=0; temp < targets.length; temp++){
                   if(targets[temp].getName().equals("managed_2")){
                        deployTargets[0]=targets[temp];
              ProgressObject processStatus=deployManager.distribute(deployTargets, new                
                        File("\\\\10.0.0.47\\Builds\\VertexTest\\domain1\\tc3.3b74_6.2.2011.19\\test.ear"), null,options);
              DeploymentStatus deploymentStatus=processStatus.getDeploymentStatus() ;
              System.out.println("UnDeploymentStayus.getMessage(): "+deploymentStatus.getMessage() );
    System.out.println("Start sleeping");
              Thread.sleep(10000);
    System.out.println("End sleeping");
              TargetModuleID[] targetModuleIDs=deployManager.getAvailableModules(ModuleType.EAR, deployTargets);
              System.out.println("\n\t targetModuleIDs [] = "+targetModuleIDs);
              for (int j=0;j<targetModuleIDs.length;j++){
                   System.out.println("\n\t "+targetModuleIDs[j]);
                   deployManager.start(targetModuleIDs);
                   deployManager.start(targetModuleIDs);
    }This code successfully deployed my application on desired managed server but my application is in 'Prepared' state instead of 'Active' state.
    Currently, I have to manually update my application's state to 'Active'.
    Can anybody tell me if I am missing something in my code.

    It actually looks fine, but what could be the problem is the time to deploy your application and
    the sleep command of ten seconds. When your sleep is finished, is your application deployment finished?
    Maybe you can add a while loop using the isCompleted method of the DeploymentStatus class, for example,
    ProgressObject processStatus = deployManager.distribute(deployTargets, new File("\\\\10.0.0.47\\Builds\\VertexTest\\domain1\\tc3.3b74_6.2.2011.19\\test.ear"), null,options);
    DeploymentStatus deploymentStatus = processStatus.getDeploymentStatus() ;
    while (!deploymentStatus.isCompleted()) {
        Thread.sleep(1000);
    TargetModuleID[] targetModuleIDs = deployManager.getAvailableModules(ModuleType.EAR, deployTargets);
    System.out.println(targetModuleIDs);
    if (targetModuleIDs.length > 0) {
        deployManager.start(targetModuleIDs);
    }Or something else along those lines.

  • Prepared statement help

    Hello all!
    I am trying to get this prepared statement to work but am getting an error that I cant understand.
    Basically I have a class file that the ps resides in. I am calling the ps from a jsp.
    Here is the code:
    public void recordUsage(String userid, String ipaddress, String page, String filename)
           String insertStatement = "INSERT INTO usageLog(userId,ipAddress, localTime, page, fileName) VALUES(?,?,?,?,?)";
                try
                {   java.util.Date currentDate=new java.util.Date();//Create a date object for the timestamp
                    java.sql.Timestamp ts=new java.sql.Timestamp(currentDate.getTime());//Create the timestamp from the above date object.
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    objConn = java.sql.DriverManager.getConnection("jdbc:odbc:sensorWeek","","");
                    PreparedStatement ps = objConn.prepareStatement(insertStatement);
                    ps.setString(1, userid);
                    ps.setString(2, ipaddress);
                    ps.setTimestamp(3, ts);
                    ps.setString(4, page);
                    ps.setString(5, filename);
                    ps.executeUpdate();
                    objConn.commit();
                    ps.close();
                    objConn.close();
                    System.out.println("recordusage method called");
                catch (SQLException s)
                    System.err.println("DataBase PROBLEM");
                    s.printStackTrace();
                catch (Exception e)
                        System.err.println("Error in recordUsage method");
                        e.printStackTrace();
    }Here is the error generated:(I hate to dump this on you)
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: sensorPac.methodClass.record(Ljava/lang/String;Ljava/lang/String;)V
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    root cause
    javax.servlet.ServletException: sensorPac.methodClass.record(Ljava/lang/String;Ljava/lang/String;)V
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
         at org.apache.jsp.download_jsp._jspService(download_jsp.java:93)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
         at java.lang.Thread.run(Thread.java:534)
    TIA!!

    And what makes you think that the above code is causing the problem?

  • Error with ExecuteQuery() in prepared statement

    Hello,
    i' m a new one at java. I' m trying to build a web application in jsp and i have a problem in a simple at log in authentication.
    My code is this:
    <html>
    <head>
    <title>Welcome to the online Boat Shop, Inc.</title></head>
    <body>
    <%@ page language ="java" import = "java.io.*, java.lang.*, java.sql.*" %>
    <% try
    String strUsername = request.getParameter("USERNAME");
    String strPassword = request.getParameter("PASSWORD");
    Class.forName ("org.apache.derby.jdbc.ClientDriver");
    Connection myConn = DriverManager.getConnection("jdbc:derby://localhost:1527/boatsdb","tony", "logo");
    String strSQL = "SELECT USERNAME, PASSWORD FROM BOATDB where USERNAME = ? and PASSWORD = ?";
    PreparedStatement stmt = myConn.prepareStatement(strSQL);
    stmt.setString(1, "USERNAME");
    stmt.setString(2, "PASSWORD");
    ResultSet myResult = stmt.executeQuery(strSQL);
    if(myResult.next()){
    out.println("Login Succesful! A record with the given user name and password exists");
    } else {
    out.println("Login Failed. No records exists with the given user name and password");
    myResult.close();
    stmt.close();
    myConn.close();
    } catch(Exception e){
    out.println(e);
    %>
    </body>
    </html>
    The problem is that prepared statement doesn't support executeQuery() method and i can find any solution. The error is this:
    java.sql.SQLException: Method 'executeQuery(String)' not allowed on prepared statement. I already have some data in my database so that it can return results.
    Thank you.
    Edited by: antonis on May 3, 2008 6:13 AM

    thank you, that was the problem. It seems that i have also done mistakes in passing the username and password from the forms to the database for checking, because the message that i get always when i log is that there is no user with this username kai password.
    <form method=GET action=log1.jsp>
    <font size=5> Username <input type=text name="USERNAME" size=20>
              </font>
              <br>
              <font size=5> Password <input type=text name="PASSWORD" size=20>
              </font>
              <br>
              <input type=submit name=action value="Submit">
    </form>
    That's the forms and combined with the code in the fist post should have worked. Any ideas?
    thanks again.

Maybe you are looking for