Prepared statements related problem

Hi,
i have this strange problem with prepared statements i think.
When i execute an insert query without prepared statements i works fine (always), when i use prepared statements it sometimes gives a db error saying i'm trying to insert a null value.
The problem is that I'm not!!!
If i were why does it work sometimes?
It may be a bug but i don't know where to look for it... is it a prepared statements, application server or db2 problem?

This is the code...
     public void insertArticolo(Articolo item) throws Exception {
          PreparedStatement ps = null;
               try {          
                    StringBuffer sql = new StringBuffer("insert into RUW.RUWT1_ARTICOLO (");
                    sql.append("C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, ");
                    sql.append("C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,");
                    sql.append("C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO");
                    sql.append(") values (");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?" + ", ");
                    sql.append("?");
                    sql.append(")");
                    ps = connectionCreatePreparedStatement(sql.toString());
                    System.out.println(sql.toString());
                    KeyArticolo keyArticolo = item.getKeyArticolo();
                    KeyPartita keyPartita = keyArticolo.getKeyPartita();
                    Ente ente = keyPartita.getKeyRuolo().getEnte();
                    System.out.println("/"+ ente.getCodEnte()+ "/");
                    System.out.println("/"+ keyPartita.getKeyRuolo().getConcessione().getCodConc()+ "/");
                    System.out.println("/"+ keyPartita.getKeyRuolo().getAnnoRuolo()+ "/");
                    System.out.println("/"+ keyPartita.getKeyRuolo().getProgRuolo()+ "/");
                    System.out.println("/"+ keyPartita.getNumPartita()+ "/");
                    System.out.println("/"+ keyPartita.getProgPartita()+ "/");
                    System.out.println("/"+ item.getKeyArticolo().getProgArticolo()+ "/");
                    System.out.println("/"+ item.getCodEntrata()+ "/");
                    System.out.println("/"+ ente.getTipoUfficio()+ "/");
                    System.out.println("/"+ ente.getCodUfficio()+ "/");
                    System.out.println("/"+ item.getTipoImposta()+ "/");
                    System.out.println("/"+ item.getAnnoImposta()+ "/");
                    System.out.println("/"+ item.getCaricoOrigine()+ "/");
                    if (item.getDescArticolo().equals("")) {
                         item.setDescArticolo(" ");
                    System.out.println("/"+ item.getDescArticolo()+ "/");
                    ps.setLong(1,ente.getCodEnte());
                    ps.setLong(2,keyPartita.getKeyRuolo().getConcessione().getCodConc());
                    ps.setLong(3,keyPartita.getKeyRuolo().getAnnoRuolo());
                    ps.setLong(4,keyPartita.getKeyRuolo().getProgRuolo());
                    ps.setLong(5,keyPartita.getNumPartita());
                    ps.setLong(6,keyPartita.getProgPartita());
                    ps.setLong(7,item.getKeyArticolo().getProgArticolo());
                    ps.setString(8,item.getCodEntrata());
                    ps.setString(9,ente.getTipoUfficio());
                    ps.setString(10,ente.getCodUfficio());
                    ps.setString(11,item.getTipoImposta());
                    ps.setLong(12,item.getAnnoImposta());
                    ps.setLong(13,item.getCaricoOrigine());
                    ps.setString(14,item.getDescArticolo());
                    ps.executeUpdate();
               catch (Exception e) {
                    e.printStackTrace();
                    connectionCloseStatement(ps);
                    throw e;
          }and this is the result of the systemout
[10/03/06 14.07.07:051 CET] 76357635 SystemOut O insert into RUW.RUWT1_ARTICOLO (C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
/13199/
/66/
/2002/
/1564/
/28330/
/1/
/2/
/0997/
/120/
/2002/
/11900/
/ /

Similar Messages

  • Passing values for a prepared statement encounters problem

    I have a query which runs fine when executed from sqlplus
    SELECT SYSDATE + (INTERVAL '10' MINUTE) FROM dual;
    The same query when run using a java statement also works well.
    when I use a Prepared statement like
    String sql = SELECT SYSDATE + (INTERVAL ? MINUTE) FROM dual;
    PreparedStatement ps = this.getPreparedStatement(sql.toString());
    ps.setString(1, "10");
    and execute I get the following exception
    ORA-00920: invalid relational operator
    I tried another way which also gives me a similar exception
    String timeout = "10";
    SELECT SYSDATE + (INTERVAL" + timeout + "MINUTE) FROM dual;
    Can anybody tell me why the problem happens. Is anything wrong in passing values dynamically for an 'interval' function in oracle?

    asokan_srini wrote:
    Yes friends
    Thanks for the reply. It worked out this way as u said
    sql.append("SELECT SYSDATE + (INTERVAL ");
    sql.append("'" + Integer.parseInt(timeout) + "' MINUTE) FROM dual");
    Mr.masijade said.
    First of all, there is no reason to do this command, really, but okay.
         There may be scenarios like this to use the command
              select * from mytable where (systimestamp - lastUpdateTimestamp) > Interval '10' Minute
    Is there any other better way to get all records updated before a certain timestamp?Use Timestamp to create a timestamp and PreparedStatement's setTimestamp(), maybe?

  • Prepared Statement - updating problem

    Hello all together!
    I've a problem and I hope somebody could help me out of misery!
    I have created a table and now I want to update a special cell and my aim is to use prepared statements
    I have generated it in the form mentioned below:
    public void setValueAt(Object newValue, int row, int col) {
    try {
    stmtPrep.setString(1, getColumnName(col)); // this should initalize the column I want to update
    stmtPrep.setObject(2, newValue); //this is the new value which should be set
    rowElements = getElementsOfRow(row);
    stmtPrep.setInt(3, (Integer.parseInt((String)rowElements[0]))); //this is my primary key
    stmtPrep.executeUpdate();
    stmtPrep.clearParameters();
    rs.updateRow();
    } catch (SQLException e) {e.printStackTrace(); }
    My SQL-Statement looks like this:
    private String queryPrep = "update Buch set ? = ? where isbn = ?";
    My problem is that column is not set.... am I not allowed to set column name in the prepared statement??
    how do I manage to show my changes in a master/detail implementation?
    anybode a clue????

    Hi majandrah,
    My SQL-Statement looks like this:
    private String queryPrep = "update Buch set ? = ?
    where isbn = ?";Sorry, not allowed.
    My problem is that column is not set.... am I not
    allowed to set column name in the prepared
    statement??No, you are not. Parameters can only be used for literal values -- not for names of columns , tables, etc.
    how do I manage to show my changes in a master/detail
    implementation?
    anybode a clue????I suggest using the java.text.MessageFormat class, like so:
    MessageFormat queryPrep = new MessageFormat("update BUCH set {0} = ? where ISBN = ?");
    String query = queryPrep.format(String[]{getColumnName(col)});
    // Now use your (posted) code, starting at line...
    stmtPrep.setObject(2, newValue);Good Luck,
    Avi.

  • Db2 - bea jdbc type 4 driver error - cursor not in a prepared state

    Hi
    I am getting this error from BEA DB2 Driver in weblogic console.
    java.sql.SQLException: [BEA][DB2 JDBC Driver][DB2]CURSOR C02 NOT IN A
    PREPARED STATE
    This problem occurs frequently almost everyday.
    When this error happens we clear the statement cache by logging in to the weblogic console (which clears the cache of prepared and callable statements maintained for each connection in the connection pool), and will be able to proceed till the error comes up again!
    Has anyone come across this type of error?
    DB2 UDB V8.1 Fixpack 4 on Solaris
    Weblogic V8.1 SP2
    Thanks
    Sireesh.

    We have seen that error as well. When using entity beans, we could do some creates, but then we would get the Cursor error. It would happen sporadically.
    IBM now has better Type 4 drivers with version 8.2, we are having better luck with them then with the BEA drivers.

  • Problem with Prepared Statement & MS Access

    Hi
    I have tried to find some info about this but can't see anything specific to what I think the problem may be. Hopefully someone can point me in the right direction.I am trying to get information out of an MS Access database using a Prepared Statement but I am getting strange results.
    When I run the query in the database it gives me the correct totals (�51) for 4 records. When I run the Prepared Statement ,I get 81. Has it got anything to do with the data type I am using( sorry if this is a really basic question). here is my code- the connection etc is elsewhere.
    private void getReportMoneyTotal() throws SQLException
              Calendar todayTotal =Calendar.getInstance() ;
               SimpleDateFormat reportDateFormat = new SimpleDateFormat("dd MM yyyy");
              PreparedStatement preparedT =context.getConnection().prepareStatement(
                   "SELECT Sum(tblSession.Fee) AS Total, Count(tblBooking.BookingID) AS CountOfBookingID FROM tblSession INNER JOIN "+
                   "(tblBooking INNER JOIN tblCustomer_Booking ON tblBooking.BookingID = tblCustomer_Booking.BookingID) ON tblSession.SessionID = tblBooking.SessionID "+
                   "WHERE (((tblBooking.EventDate)>DateAdd('m',-1,#"+reportDateFormat.format(todayTotal.getTime())+"#)) AND ((tblSession.Session)='Morning' Or (tblSession.Session)='Evening')) OR (((tblSession.Session)='Afternoon') AND ((tblBooking.Extension)=Yes))"
              ResultSet resultTotal =preparedT.executeQuery();
              resultTotal.next();
              Double total =resultTotal.getDouble("Total");
              Locale locale = new Locale("GBP");
            NumberFormat gbpFormat = NumberFormat.getCurrencyInstance(locale);
              System.out.println(gbpFormat.format(total));
              preparedT.close();
         }I do realise that my code probably isn't very elegant but I'm only learning!

    Hi Matt--
    I am not clear if you are saving the url with the # # around
    the text or if
    the
    data already contains the # marks.
    When you insert a link, you want to make sure you insert is
    insert into table ( link1) values ( <cfqueryparam
    cfsqltype="cf_sql_varchar"
    value='#linkvaluehere#'> )
    remember to
    1) enclose your data's value inside quotes (some databases
    are picky about
    single v. double quotes).
    2) if it IS in quotes, swap doubles for singles and see if
    that helps.
    3) make sure your data being saved is NOT double hashed like
    '##linkvalueher##'. Double ##'s tell
    Coldfusion not to treat it as a variable.
    hope his helps,
    tami
    "Mattastic" <[email protected]> wrote in
    message
    news:f9c7h0$8ub$[email protected]..
    | Hi Folks,
    |
    | I'm storing a link in a nvarchar field in SQL server,
    www.foo.co.uk, it
    looks
    | and works fine in SQL server. Problem occurs when I setup
    an ADP in Access
    and
    | insert links. Certain links have a hash symbol around them.
    so
    |
    http://www.foo.co.uk, would be #
    http://www.foo.co.uk# which is
    causing
    problems.
    |
    | Can anyone tell me why this is happening? and how to stop
    it?
    |
    | Thankyou
    |

  • Problem in inserting to MS Access using prepared statement

    I am inserting a record in MS Access db and I am using prepared statement. I am encountering an error.... any help I would really appreciate it. So much time figuring out what the problem is....
    ConvertText contxt = new ConvertText();
    String bday = (String)cbYear.getSelectedItem() +
    cbMonth.getItemCount()+(String)cbDay.getSelectedItem();
    try{
    // load MySQL driver
    Class.forName(driver);
    // Setup connection to DBMS
    Connection conn = DriverManager.getConnection(url);
    // Create statement     
    Statement stmt     = conn.createStatement();
    PreparedStatement insertPersons = conn.prepareStatement(
            "INSERT INTO PERSONS VALUES(" +
         "FIRST_NAME               = ?," +
         "LAST_NAME              = ?," +
         "MIDDLE_NAME               = ?," +
         "NICKNAME              = ?," +
         "GENDER              = ?," +
         "MARITALSTATUS           = ?," +
         "AGE                    = ?," +
         "BIRTHDATE                   = ?," +
         "ADDRESS                  = ?," +
         "RES_PHONE_NUMBER        = ?," +
         "OFFICE_PHONE_NUMBER     = ?," +
         "CELL_NUMBER               = ?," +
         "COMPANY_NAME               = ?," +
         "EMAIL_ADDRESS               = ?," +
         "TIMESTAMP               = ?)"
              insertPersons.setString   (1, tfFirstName.getText());
              insertPersons.setString   (2, tfLastName.getText());
              insertPersons.setString   (3, tfMiddleName.getText());
              insertPersons.setString   (4, tfNickName.getText());
              insertPersons.setString   (5, (String)cbGender.getSelectedItem());
              insertPersons.setString   (6, (String)cbMaritalStatus.getSelectedItem());
              insertPersons.setInt      (7, contxt.formatStringToInt(tfAge.getText()));
              insertPersons.setDate     (8, contxt.formatStringToSQLDate(bday));
              insertPersons.setString   (9, tfAddress.getText());
              insertPersons.setString   (10,tfResPhoneNumber.getText());
              insertPersons.setString   (11,tfOffPhoneNumber.getText());
              insertPersons.setString   (12,tfCellNumber.getText());
              insertPersons.setString   (13,tfCompanyName.getText());
              insertPersons.setString   (14,tfEmailAddress.getText());
              insertPersons.setTimestamp(15, new Timestamp(System.currentTimeMillis()));          
              insertPersons.executeUpdate();
              conn.close();          
    JOptionPane.showMessageDialog(null,"Record Inserted!", "INSERT",
                        JOptionPane.INFORMATION_MESSAGE);
    }catch (SQLException ex){
    System.err.println("==> SQLException: ");
    System.out.println("Message:   SQL Exception");
    System.out.println("Message:   " + ex.getMessage ());
    System.out.println("SQLState:  " + ex.getSQLState ());
    System.out.println("ErrorCode: " + ex.getErrorCode ());
    JOptionPane.showMessageDialog(null, ex.getMessage() + ex.toString(),"Error", JOptionPane.INFORMATION_MESSAGE);
    }catch(Exception ex){
    }          ERROR Displayed:
    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 30. java.sql.SQLException     

    Hi cruzdhel,
    Your SQL looks incorrect to me.
    I am not familiar with that syntax.
    I think it should be like this:
    PreparedStatement insertPersons =
    conn.prepareStatement("INSERT INTO PERSONS (FIRST_NAME," +
                                               "LAST_NAME," +
                                               "MIDDLE_NAME," +
                                               "NICKNAME," +
                                               "GENDER," +
                                               "MARITALSTATUS," +
                                               "AGE," +
                                               "BIRTHDATE," +
                                               "ADDRESS," +
                                               "RES_PHONE_NUMBER," +
                                               "OFFICE_PHONE_NUMBER," +
                                               "CELL_NUMBER," +
                                               "COMPANY_NAME," +
                                               "EMAIL_ADDRESS," +
                                               "TIMESTAMP)" +
    "values (?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?," +
            "?)");Hope this helps.
    Good Luck,
    Avi.

  • Problems with Prepared Statement

    Hi,
    I am developing an Java Bean that reads from a database of Entertainments of my home city of Glasgow and displays that info to a text area. I want the User to input the type of Entertainment they want e.g. Bars or Clubs, and the name of the place they want to go and then the Java Bean displays the info of the specified place.
    The program works fine if I set the Query to display the data from the database but I want the User to define the query by thier input.
    So I used Prepared Statements, but I have error messages saying that
    Syntax Error in FROM Clause
    my code to query the database is shown below
    String query ="SELECT * FROM ? WHERE Name=?";
    PreparedStatement PresStatement=con.prepareStatement(query);
    //my input to test Database.will change to variable
    PreStatement.setString(1,"Pubs");
    PreStatement.setString(2,"Admiral");
    ResultSet rs=PreStatement.executeQuery();The Problem seems to the placholder after the FROM clause but I can't seem to fix it.
    Any Help would be greatly appreciated.
    Regards
    Brian

    just a guess here, but I'd imagine it's because of the way PreparedStatement handles Strings. Obviously, if you're using a String as part of your SQL query, you're going to want single quotes around the entire thing. Thus, the first setString() is probably trying to put single quotes around the table name, which could be causing problems.
    You don't really lose anything if you just work around this by changing your code to..
    tableName = "Pubs"; //or this is probably coming from your user
    String query ="SELECT * FROM "+tableName+" WHERE Name=?";
    PreparedStatement PresStatement=con.prepareStatement(query);
    //my input to test Database.will change to variable
    PreStatement.setString(1,"Admiral");
    ResultSet rs=PreStatement.executeQuery();

  • Problem with Oracle Prepared Statement

    Hi all,
    Please help me..
    I Have 2 pages, in first page i had table with rows with update image for each row, when i click update it leads to 2nd page which shows the particular row information
    my problem is, i am executing prepared statement with 2 parameters in 2nd page controller which is working fine first time, when i go to first page and comes to 2nd page again my
    result set showing Null, some times query executing and getting results, some times null, i am confused with this behaviour. please help me ..
    Thanks all

    Hi ,
    How your table is being popluated ? You have executed VO in PR or PFR ?
    Please give snippet of your CO code , both after navigating from first page to second and again after coming back to first page .
    Also is same AM is retain or not ?

  • Prepared Statement 8.1.7 problem with spaces

    I have a char field that is char(10). It has characters like '39' stored in it. That is of course space filled.
    When I try to use that field in a select statement where clause in a prepared statement it does not return any rows.
    However, if I define the column as char(2) it works. If I define the column as varchar2(10) and put '39' in it (2 length) it works.
    What is the problem anyone? I am using Java 1.3.1, and the Oracle JDBC thin client newest .jar file (12) for Oracle8.i
    I have seen others have this problem but no solutions?

    Update to problem
    I have the latest (classes12.zip) JDBC drivers from Oracle.
    We are running Oracle 8.1.6 and converting to Oracle 8.1.7.
    This works the same with both.
    Example, I have a column (char(10)) with trailing spaces. i.e. '39 '.
    When I perform a Prepared Statement with that column in the where clause, it returns no result rows.
    When I perform a standard statement with that column in the where clause, it returns rows.
    When I define a column char(2) and use it in the where clause it works fine.
    When I define a column varchar2(10) and load it with data like '39', it works fine.
    When I define a column varchar2(10 and load it with data like '39 ', it does not work.
    When I execute this same Prepared Statement through the jdbc:odbc bridge it works fine.
    I cannot change the definition of the columns as they are foreign key data. What is the problem here? Any help is appreciated.
    If you need further information please feel free to contact me.

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

  • Prepared statement problem

    I am trying, for some time now, to implement some sort of bank application that uses DBs to store customers.
    I have been trying to improve my code, the results are interesting since while studing more I saw that the previous code was.....not so good. I am using Prepared statement now as some of you suggested but I cannot surpass this final glich.
         try
                                      try
                                           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                            Connection connection=DriverManager.getConnection("jdbc:odbc:customersTable");
                                            Statement stat = connection.createStatement();
                                            ResultSet set = stat.executeQuery("SELECT * FROM CUSTOMERSTABLE");
                                            boolean check = true;
                                            while(set.next())
                                                 String ssnChecked = ssn.getText();
                                                 String SSN = set.getString("ssn");
                                                 if(ssnChecked.equals(SSN))
                                                      JOptionPane.showMessageDialog(null, "SSN already excists");
                                                      check = false;
                                            if(check == true)
                                                  String ssnToDB = ssn.getText();
                                                 String nameToDB = name.getText();
                                                 String surnameToDB = surname.getText();
                                                 String addressToDB = address.getText();
                                                     String phoneToDB = phone.getText();
                                                 String phone2ToDB = phone2.getText();
                                                 String balanceToDB = balance.getText();
                                                 System.out.println(ssnToDB+nameToDB);
                                                 PreparedStatement prstat = connection.prepareStatement("INSERT INTO CUSTOMERSTABLE VALUES ( ????????)");
                                                 prstat.setString(1,ssnToDB);
                                                 prstat.setString(2,nameToDB);
                                                 prstat.setString(3,surnameToDB);
                                                 prstat.setString(4,addressToDB);
                                                 prstat.setString(5,phoneToDB);
                                                 prstat.setString(6,phone2ToDB);
                                                 prstat.setString(7,balanceToDB);
                                                 prstat.executeUpdate();
                                                 prstat.close();
                                                 //String command = "INSERT INTO CUSTOMERSTABLE VALUES ("+ssnToDB+nameToDB+surnameToDB+addressToDB+addressToDB+phoneToDB+phone2ToDB+balanceToDB+")";
                                            connection.close();
                                      catch(ClassNotFoundException exception)
                                           JOptionPane.showMessageDialog(null, "ERROR1");
                                 catch(SQLException exception)
                                      JOptionPane.showMessageDialog(null, "ERROR2");
                                 }This code throws a SQLException that probably has to do with the use of PreparedStatement. Can you help?

    java.sql.SQLException: [Microsoft][&#9576;?&#8319;&#942;?&#940;&#905;&#905;&#940; &#910;&#970;&#9616;&#942;&#973;&#8804;&#973;&#8805; ODBC Microsoft Access]&#9532;&#8804;?&#940;
    &#904;&#905;&#9612;&#906;&#910; &#911;&#943;&#970;&#9600;&#910; COUNT
    ????????????

  • Problem in Wilcard Search (%) with Prepared Statement

    Hello Everyone,
    Im trying to search using the like operator within a prepared statement. The program compiles , but when I execute it I get an empty result set.
    I tried the same query in Query Analyser in SQL Server 2000 and it worked flawlessly.
    I searched on this forum also and I read recommendations suggesting
    to put the ? in like '?'   This gives me an error.
    Ive tried all options I could get my hands on ,now I request you all to please provide me some guidance.
    Thankyou
    The code snippet is as follows :
              String  sDay= "%"+startDay+"%";
                    ps= con.prepareStatement("Select  *  from Testdb  where days like ? ");
              ps.setString(1,sDay);
              As I said earlier, this query returns and empty result set.
    Thankyou once again.

    Its next to impossible for me to switch to Statement from prepared S. because the Query has got way to many conditions and its next to impossible to handle all those in a statement.
    I had originally started out with statement itself but then I switched to prepared statement as it was getting unmanageable.
    I'll try finding a work around whereby I split the query into two parts using the manageable part and the Wilcard search in the statement and the other unmanageable part in the PS.
    Else I will again have to attempt that. I had also had a feeling this was affecting it.
    Thanks for the help.
    If anyone has some solution please post it .
    Thank you.

  • Deployments are in Active state on Cluster but in Prepared state on server

    Hi,
    We initially deployed our application (Oracle Identity Manager 11gR2) on standalone managed server and then convert it into cluster using wlst commands.
    readDomain('/app/oracle/Middleware_OAM/user_projects/domains/oim_domain')
    setDistDestType('JRFWSAsyncJmsModule', 'UDD')
    setDistDestType('OIMJMSModule', 'UDD')
    create('oim_cluster','Cluster')
    assign('Server','oim_server1','Cluster','oim_cluster')
    updateDomain()
    The cluster is created fine and we can start the application successfully and access it. However the problem is that all the deployments are in 'Active' state only under Cluster but in prepared state under the server oim_server1 (though application access working on managed server port). Please advise where we are missing and what could be the wrong?
    Thanks

    Hi,
    1. What if you are trying to access the application page, does it come up ?
    2. Use the below wlst command to get the actual state of the deployed application:
    The deploy command returns a WLSTProgress object that you can access to check the status of the command. The WLSTProgress object is captured in a user-defined variable, in this case, progress.
    wls:/mydomain/serverConfig/Servers> progress= deploy(appName='businessApp',path='c:/myapps/business',createplan='true')
    The previous example stores the WLSTProgress object returned in a user-defined variable, in this case, progress. You can then use the progress variable to print the status of the deploy command. For example:
    wls:/mydomain/serverConfig/Servers> progress.printStatus()
    Current Status of your Deployment:
    Deployment command type: deploy
    Deployment State       : completed
    Deployment Message     : null
    wls:/mydomain/serverConfig/Servers>
    3. Restart all the servers, instances, related DB and check if it helps.
    Thanks,
    Sharmela

  • Database prepared statements Flooding

    Hi Friends,
    Need your help to fix this prolonging problem in one of our applications. We observe that the following queries are declared as prepared statements but have dynamic value ROWID in each.
    SELECT ROWID, C. * FROM Table1 C WHERE C.VENDORLOGINID = ? AND C.VENDORTYPE = ? AND (ROWID = _ ROWID100)
    SELECT ROWID, C. * FROM Table2 C WHERE C.VENDORIDCH = ? AND (ROWID = _ ROWID114)
    SELECT ROWID, C. * FROM Table1 C WHERE C.VENDORLOGINIDBASE = ? AND C.VENDORTYPE = ? AND (ROWID = _ ROWID58)
    This results in a FLOOD of prepared statements (over 3000) as it is an application with a very large DB.
    We found out that a newer version of Ojdbc14.jar (10.2.0.3.0) is available (At present we are shipping the product with 10.2.0.1.0). We tested with this newer jar and found out bind variables are not treated as dynamic variables with this jar file. SQL queries are getting cached as expected.
    This new jar file did fix the problem when our DB was 10g for the application (another), but for this current application we are using Oracle 9i.
    The same jar file does not seem to be fixing the issue.
    Has anybody faced similar issue before?
    Ideally the 10g jar file should eb backward compatible but for some reason it is not for this particular problem.
    Please can somebody help to get a solution for this problem. Do let me know if you need more information.
    Thanks.

    This thread is old and undiscussed since first post.
    Don't understand why but i got some ideas.
    1. First of all, i doubt that this is JDBC issue. JDBC PreparedStatement caching has nothing to do with sharability of SQL statements in Oracle.
    If this is JDBC issue, what a silly bug it is... But silly things happen quite often :(
    2. I think some cursor-related views like V$SQL_SHARED_CURSOR, V$SQL and V$SQLAREA should be investigated. The notorious bind mismatch can cause unwanted unshareable SQL statements which look exactly same each other.

  • How do I handle NULL returns from prepared statement?

    Thanks in advance to all those who respond. As a beginner with Java/JSP/JDBC, I need all the help I can get!
    Here's the problem...
    I'm using a prepared statement in JSP to query a MySQL database.
    If there is a value to return, everything works properly.
    If the query returns a NULL (empty set) value, I get the following error:
    javax.servlet.ServletException: Before start of result set
    Here's the code (no negative comments please...I know I'm violating some conventions! I'll restructure it later. Right now I just need help with handling the NULL case):
    <%
    Driver DriverAppt = (Driver)Class.forName(MM_test_DRIVER).newInstance();
    Connection ConnAppt = DriverManager.getConnection(MM_test_STRING,MM_test_USERNAME,MM_test_PASSWORD);PreparedStatement StatementAppt = ConnAppt.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id = " + Recordset1__MMColParam + " AND year = " + yy + " AND month = '" + months[mm] + "' AND date = " + dates[dd] + " AND appttime = '16:15:00'");
    ResultSet Appt = StatementAppt.executeQuery();
    boolean Appt_isEmpty = !Appt.first();
    boolean Appt_hasData = !Appt_isEmpty;
    Object Appt_data;
    int Appt_numRows = 0;
    %>
    Thanks for the help!!!

    I think I have a better handle on what's occurring here. To cut to the heart of the problem, I'm going to give a very simple example that illustrates what type of error handling I need.
    HERE'S THE EXAMPLE:
    Let's say that I have a database of users. There are only two columns in the database: user_id and lastname. There are only 2 users, user_id "1" has lastname "Jones" and user_id "2" has lastname "Smith".
    I built a very simple web interface that let's a user enter a number to see if there's a lastname associated with that record. The user has no way of knowing if the user_id exists or not, so they may or may not enter a valid number.
    If the user enters a valid user_id (in this case "1" or "2"), then the correct lastname is displayed. If the user enters an invalid user_id (in this case, anything other than "1" or "2") then I get the same "Before start of result set" error that I'm getting in my real application.
    So, the question is: WHERE IN THIS CODE WOULD I HANDLE THE RETURN OF AN EMPTY SET?
    The goal here is to have the sentence say "The user's lastname is .", basically returning null. If there has to be a value, then have the last sentence say "The user's lastname is unknown."
    If you can solve this simple example, you'll have also solved the problem with my main application!!!! :-)
    Here's the example code:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <%@ include file="Connections/example.jsp" %>
    <%
    String Recordset1__MMColParam = "1";
    if (request.getParameter("user_id") !=null) {Recordset1__MMColParam = (String)request.getParameter("user_id");}
    %>
    <%
    Driver DriverRecordset1 = (Driver)Class.forName(MM_example_DRIVER).newInstance();
    Connection ConnRecordset1 = DriverManager.getConnection(MM_example_STRING,MM_example_USERNAME,MM_example_PASSWORD);
    PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM test_table WHERE user_id = " + Recordset1__MMColParam + "");
    ResultSet Recordset1 = StatementRecordset1.executeQuery();
    boolean Recordset1_isEmpty = !Recordset1.next();
    boolean Recordset1_hasData = !Recordset1_isEmpty;
    Object Recordset1_data;
    int Recordset1_numRows = 0;
    %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form action="test.jsp" method="get" enctype="application/x-www-form-urlencoded" name="form1" target="_self">
    <p> Submit a user id and a lastname will be displayed.</p>
    <p>
    <input type="text" name="user_id">
    <input type="submit" name="" value="Submit">
    </p>
    </form>
    <p>The User's lastname is <%=(((Recordset1_data = Recordset1.getObject("lastname"))==null || Recordset1.wasNull())?"":Recordset1_data)%>.</p>
    </body>
    </html>
    <%
    Recordset1.close();
    StatementRecordset1.close();
    ConnRecordset1.close();
    %>
    A huge "THANK YOU!!!!" to all those who've helped me here!!!

Maybe you are looking for

  • Identifying Changed Dates on Documents in SAP B1

    Greetingsu2026I have an unusual request that is somewhat long, very serious, and hope folks can help.  A headquarters customer believes a subsidiary company has u2018made upu2019 dates on invoices for previous billings.  They describe the date change

  • Do I need to get a separate program to burn multiples copies of a DVD on Mac?

    Do I need to get a separate program to burn multiples copies of a DVD on Mac, and not have the copies separate into AUDIO_TS and VIDEO_TS?  I made a series of lesson plans on iMovie.  When it opens on the original disk, it goes right to my music and

  • Spry submenu not loading correctly in IE

    Solved: check out this link http://forums.creativecow.net/thread/191/857297 QUESTION: Hi, I am new to spry and this is my first menu. I cannot for the life of me figure out why the submenu will not load correctly in IE. It is loading at the top of th

  • Unwanted bookmarks, word 2007

    Hi, I'm using Word 2007 and the trial version von Acrobat Pro 9 V9.3.0 in Windows 7 (all german versions). I created a word document with many headings (heading 1 to 5). I want to convert this doc into a pdf file, but I only want the headings 1 and 2

  • My wifi button not working

    my wifi button not working. i can't working any body can help me