How to use data in a ResultSet when only one record in set?

Hi.
Using a prepared statement which invokes a SELECT * from <table> where <primary key> = <unique value>.
This is executed and the results sent to a resultSet.
The only problem is that only one entry is in the resultSet. I want to parse the results and invoke a new class based on the results.
So I have:
statement = conn.prepareStatement ("SELECT First_Name, Last_Name, Street, Unit, City, Province, Postal_Code" +
" from Customer where CustomerID = ?");
statement.setInt (1, custID);
rset = statement.executeQuery();
rset.next();
cust = new Customer (custID,
rset.getString ("First_Name"),
rset.getString ("Last_Name"),
rset.getString ("Street"),
rset.getString ("Unit"),
rset.getString ("City"),
rset.getString ("Province"),
rset.getString ("Postal_Code"));
statement.close();
rset is a ResultSet. And I'm pretty sure that something like this is WRONG. But one thing I want to know, is there ANY way to properly parse a resultset with only one record?
Thanks.

I think I should clarify what I was doing: I'm trying to insert a record into a table, and with the ID that I obtain, use it to retrieve the data.
I did put a commit in there, but someone suggested that the commit won't work in this scenario.
Here is bits of the code that I'm using. By the time insertCustomer is invoked, custID is already populated. The insert works because I checked the table afterwards using a sql query and all my entries posted are there.
    private void insertCustomer (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            conn = DriverManager.getConnection (url, userid, password);
            statement = conn.prepareStatement ("INSERT INTO CUSTOMER (CustomerID, First_Name, Last_Name," +
                    " Street, Unit, City, Province, Postal_Code) values (?, ?, ?, ?, ?, ?, ?, ?)");
            statement.setInt (1, custID);
            statement.setString (2, firstname);
            statement.setString (3, lastname);
            statement.setString (4, address);
            statement.setString (5, unit);
            statement.setString (6, city);
            statement.setString (7, province);
            statement.setString (8, postalcode);
            statement.executeUpdate();
            conn.commit();          
            statement.close();
        catch (SQLException e)
            throw new ServletException (e);
        finally
            try
                if(statement != null)
                    statement.close();
                if(conn != null)
                    conn.close();
            catch (SQLException e)
                throw new ServletException(e);
    private String getCustRec (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
        Connection conn = null;
        PreparedStatement statement = null;
        ResultSet rset = null;
        CustomerJDBC cust = null;
        try
            conn = DriverManager.getConnection (url, userid, password);
            statement = conn.prepareStatement ("SELECT First_Name, Last_Name, Street, Unit, City, Province, Postal_Code" +
                    " from Customer where CustomerID = ?");
            statement.setInt (1, custID);
            rset = statement.executeQuery();
            rset.next();
            cust = new CustomerJDBC (custID,
                    rset.getString ("First_Name"),
                    rset.getString ("Last_Name"),
                    rset.getString ("Street"),
                    rset.getString ("Unit"),
                    rset.getString ("City"),
                    rset.getString ("Province"),
                    rset.getString ("Postal_Code"));
            statement.close();
        catch (SQLException e)
            throw new ServletException (e);
        finally
            try
                if(statement != null)
                    statement.close();
                if(conn != null)
                    conn.close();
            catch (SQLException e)
                throw new ServletException(e);
        return "/CustomerCreatedJDBC.jsp";
    }The Constructor method of the class CustomerJDBC appears something like this:
public CustomerJDBC (int id, String fname, String lname, String addr, String unit, String city, String prov, String pcode)
        this.custID = id;
        this.firstname = fname;
        this.lastname = lname;
        this.address = addr;
        this.unit = unit;
        this.city = city;
        this.province = prov;
        this.postalcode = pcode;     
    }Thanks for your help.
Edited by: tahna_los on Nov 16, 2008 11:49 PM

Similar Messages

  • How to get Safari to suggest passwords when only one field is present?

    Safari works great when there are two fields to enter a password - a password field followed by a "confirm password" field - but doesn't seem to work when there is only one field to enter a new password.  Any suggestions?

    Hi,
    we have done something like this using seltab.
    One inputfield, user can enter anything same like in google like
    name:ab*,dob:1972
    write a conversion method to parse this input to seltab like
        clear ls_seltab.
        ls_seltab-sign  = 'I'.
        if lv_value cs '*'.
          li_lng = sy-fdpos.
          ls_seltab-option = 'BT'.
        else.
          ls_seltab-option = 'EQ'.
          ls_seltab-low    = lv_value.
        endif.
    use your seltab to retrieve data from the table.
    In anyway.. you can search resources in this direction to build your solution.

  • How to use java source in Oracle when select by sqlplus.

    How to use java source in Oracle when select by sqlplus.
    I can create java source in Oracle
    import java.util.*;
    import java.sql.*;
    import java.util.Date;
    public class TimeDate
         public static void main(String[] args)
    public String setDate(int i){
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(new Date((long)i*1000));
    System.out.println("Dateline: "
    + calendar.get(Calendar.HOUR_OF_DAY) + ":"
    + calendar.get(Calendar.MINUTE) + ":"
    + calendar.get(Calendar.SECOND) + "-"
    + calendar.get(Calendar.YEAR) + "/"
    + (calendar.get(Calendar.MONTH) + 1) + "/"
    + calendar.get(Calendar.DATE));
    String n = calendar.get(Calendar.YEAR) + "/" + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE);
         System.out.print(n);
         return n;
    I have table name TEST
    ID DATE_IN
    1 942685200
    2 952448400
    When I write jsp I use method setDate in class TimeDate
    The result is
    ID DATE_IN
    1 1999/11/16
    2 2003/7/25
    Thanks you very much.

    It is unclear where you are having a problem.  Is your issue at runtime (when the form runs in the browser) or when working in the Builder on the form?
    Also be aware that you will need to sign your jar and include some new manifest entries.  Refer to the Java 7u51 documentation and blogs that discuss the changes.
    https://blogs.oracle.com/java-platform-group/entry/new_security_requirements_for_rias
    http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html

  • HT1695 I know nothing about how to use my new ipod and when reading the little bit of information in the folder that came with it, all I can do is turn it on, but it just powers down after a few seconds.  How do I work this thing?

    I know nothing about how to use my new ipod and when reading the little information that came with it, all I can do is turn it on.  Then in a few seconds it goes black, never having brought up a screen to do anything!  Help!  What do I do to get this thing going?

    You might consider connecting it to the charger and charging up the battery overnight.
    Please Get the iPod Touch User Manual for iOS 5

  • How to  use data function using characterstics variable for calculation on

    how to  use data function using characterstics variable for calculation on  attribute as key figure

    Hi Gayatri
    Did you not see my answer for CASE because CASE does indeed offer the use of the BETWEEN clause, but DECODE does not. Let me give you a little synopsis of DECODE.
    In its most simple form it takes 4 values and looks like this: DECODE(A, B, C, D)
    This essentially means, IF A = B THEN C ELSE D
    The trick to solving BETWEEN in a DECODE is to work out algoriths where A = B. Because we don't know how many values are between 00 and 99, although I could guess there were 100 we could of course have 100 parts in the DECODE but that would be awful. How about if we look at it another way and say this:
    IF PART_NUMBER < 'SDK00' THEN pay_amount
    ELSE IF PART_NUMBER > 'SDK99' THEN pay_AMOUNT
    ELSE pay_amount + 100
    This statement only had 2 hard coded values, but how to make DECODE work with less than? Easy, we use the LEAST function. The LEAST function takes 2 values and returns the one with the lowest value. So I use LEAST(PART_NUMBER, 'SDK00') then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the opposite function GREATEST. Putting all of this together then, you can do this:
    DECODE(PART_NUMBER, GREATEST(PART_NUMBER, 'SDK00'), DECODE(PART_NUMBER, LEAST(PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)
    In English this can be read as follows:
    IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0
    Best wishes
    Michael

  • How to use ADF variables in C:when test?

    I have a <af:iterator in my page fragment as follows
    <af:iterator id="i1" value="#{queryModel.currentDescriptor.conjunctionCriterion.criterionList}" var="criterion" varStatus="vs">
    Within this iterator, I want to make a decision absed on the index of the iterator. To do this test, I am using jstl as follows
    <c:when test="${vs.index == '0' or vs.index == '2' or vs.index == '4'}">
    This test is however always evaluating to false. I have tried cahnging my code using various combiantion as below ...
    <c:when test="#{vs.index == '0' or vs.index == '2' or vs.index == '4'}">
    <c:when test="${vs.index == 0 or vs.index == 2 or vs.index == 4}">
    <c:when test="${vs.index == '0' || vs.index == '2' || vs.index == '4'}">
    But nothign seems to be working fine.
    Can some one help me with what I am doing wrong?
    Thanks.

    How to use ADF variables in <C:when test?

  • Can u  tell me any of you how to use Date class

    Can u tell me any of you how to use Date class. Please send me the source code.

    People won't send you the source code.
    Ask specific questions. You are very vague.
    Tell me how to build.

  • Phone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    Both my iphone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    This post has already been answered. Why are you plugging your own site with an answer that has already been given? Not to mention that the information you are handing out is incorrect. There is no bug, there is no patch, and no one needs to delete any email addresses. If you take the time to read the posts with the correct answers, you will see that the solution is totally different than the erroneous one you have posted.
    GB

  • How to use utl_ftp package to transfer files from one system to another

    Hi all,
    How to use utl_ftp package to transfer files from one system to another using plsql procedure .
    I failed to find the appropriate document ,kindly help me .
    Thanks,
    P Prakash

    prakash wrote:
    I am sorry tell you, this blog is not enough to for me.It's not a blog, it's Chris' website where you download the package from. Once you download the package and unrar it, then the package spec gives instructions (and I think there's instructions on how to install it too).
    Kindly let me know if there is any oracle documentation for this .It's not an Oracle created package, it was created by Chris. It's based around the UTL_TCP package if you really want to get into the nitty gritty of how it works, but I don't think you do.

  • How to use open cursor and iner join in one statement

    Hello All,
    Could any one post the code for the below question?
    How to use open cursor and iner join in one statement
    Regards,
    Lisa

    OPEN CURSOR c FOR SELECT     carrid connid fldate bookid smoker
                        FROM     sbook innerjoin shook
                        ORDER BY carrid connid fldate smoker bookid.
    Pls reward if helpful.

  • When I import an Album or Folder from my computer that is a Various Artist Album it creates as many albums by the same name as there are songs?  How do I fix this so it is only one Album?

    When I import an Album or Folder from my computer that is a Various Artist Album it creates as many albums by the same name as there are songs?  How do I fix this so it is only one Album?

    Before you begin the import, edit the properties of the tracks to set the Album Artist to Various Artists and Part of a Compilation to Yes.
    For more info. see Grouping tracks into albums.
    tt2

  • How to reduce data usage on ipad wifi only version.  consuming **** lot of data even on simple surfing of sites

    how to reduce data usage on ipad wifi only version.  consuming **** lot of data even on simple surfing of sites

    iPhone User Guide (For iOS 4.2 and 4.3 Software)

  • [svn:osmf:] 14476: DVR: using Date instead of getInterval to do local recording timing.

    Revision: 14476
    Revision: 14476
    Author:   [email protected]
    Date:     2010-03-01 05:24:17 -0800 (Mon, 01 Mar 2010)
    Log Message:
    DVR: using Date instead of getInterval to do local recording timing.
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/net/dvr/DVRCastDVRTrait.as
        osmf/trunk/framework/OSMF/org/osmf/net/dvr/DVRCastNetConnectionFactory.as
        osmf/trunk/framework/OSMF/org/osmf/net/dvr/DVRCastRecordingInfo.as
        osmf/trunk/framework/OSMF/org/osmf/net/dvr/DVRCastTimeTrait.as
        osmf/trunk/framework/OSMFTest/org/osmf/net/dvr/TestDVRCastRecordingInfo.as

    Are you trying to record to "live" application which comes with default installation of FMS, if you are doing that then you will get Record.NoAccess as "live" application does not allow recording. Now hopefully you have FMIS and not FMSS. If you are having FMSS, you will just get live & vod apps and both of them you wont be allowed to record.
    Now I will assume you have FMIS :
    Please use other app to record other than "live". Renaming "live" to "live_test" or changing its location wont help, you will still get error.
    In order to record do following things,
    1. Create a folder called "recordApp" - since you are triggering record from client side you dont need any server-side code.
    2. Just change application name in your client connection URL to connect to "recordApp" instead of "live_test"
    3. You dont have to change anything in fms.ini so keep the default as it comes in installation.
    4. As mentioned by JayCharles please use :http://livedocs.adobe.com/flashmediaserver/3.0/docs/help.html?content=03_configtasks_37.ht ml for doing VirtualDirectory settings so that you can record your files in particular directory. (However I would note one thing is that VirtualDirectory feature is more for play than record/ingest)
    5.Give write permissions to your folder where you would be recording.
    please let me know if this does not work

  • No tabs are showing when only one window open. How do I open a new tab?

    Just upgraded to latest version. When only one window is open, no tabs show across the top. If I have two tabs open, both show across the top, but go to no tabs if I close one of them. And, the + sign is available for opening a third tab if at least two are open. The only way I can find to open a new tab when only one window is currently open is to turn off the menu, click the orange Firefox drop-down, and click New Tab. Why isn't it showing a tab, and a + tab (to open a new one) when only one tab (window) is open.

    Thanks everyone for the quick responses. Cntl + T works fine, and I did move the + window to the nav bar, which also works well.
    I had already gone into options and checked the box for always showing the tab bar, but it doesn't show it. I even unchecked it, saved the settings, the rechecked and saved the settings. Doesn't seems to make any difference.
    I'm okay with it not showing a tab when I only have one open, just so I can get to a new one easily when I want it.

  • I am getting only one record from table data

    Hi Experts,
    I am using interacive forms to bring the table data i used  GET_STATIC_ATTRIBUTES_TABLE
    method. initially the table is empty when i fill some records more than one it is giving me only one record.
    where as i fill the table in wddoinit more than one record and try to retreived it, showing all the records more than one. waht is the reason.. if i fill manually why it is not bringing all the reocrds.
    i have used the cardinatly as follows
    1. parent node(no tables/structure used)
    Dictionary structure       empty not used
    Cardinality 1..1
    Selection 0..1
    Initialization Lead Selection  Checked
    Singleton    Not checked
    Supply Function  not used
    2. table node(i used table type)
    Dictionary structure    SFLIGHT_LIGHT
    Cardinality 1..n
    Selection 0..n
    Initialization Lead Selection  Checked
    Singleton    Not checked
    Supply Function  not used
    Pleae help me out...
    Thanks,
    Mahesh.Gattu

    hi,
    Use the following code for making the rows editable for a table UI element.
      DATA lo_nd_cn_try TYPE REF TO if_wd_context_node.
      DATA lo_el_cn_try TYPE REF TO if_wd_context_element.
      DATA ls_cn_try TYPE wd_this->element_cn_try.
      DATA ls_cn_try1 TYPE wd_this->elements_cn_try.
    navigate from <CONTEXT> to <CN_TRY> via lead selection
      lo_nd_cn_try = wd_context->get_child_node( name = wd_this->wdctx_cn_try ).
    do 5 times.                       
    clear ls_cn_try.
    append ls_cn_try to ls_cn_try1.
    lo_nd_cn_try->bind_table( ls_cn_try1 ).
    enddo.
    ->  cn_try is the node which is binded with the Table UI element.
    What all this is called as initialization of table. This code will make 5 rows editable, If u want more rows editable then run the loop according to the requirement.
    U can write this code in the WDDOINIT.
    Thanks,
    Pankaj Aggarwal.

Maybe you are looking for

  • AX 2012 Enterprise portal issue.

    We have EP site on AX 2012 and the version of SharePoint is 2010 (Enterprise) RTM. Once is a day, we get the following error, but after recycling the application pool of the enterprise portal the error is gone. Message: An unhandled error has occurre

  • I didnot purchase this item nursing certification exam flash cards pediatric ccns exam flash card study system on 09/21/12 at 3:37am in the morning Order

    I didnot purchase this item nursing certification exam flash cards pediatric ccns exam flash card study system on 09/21/12 at 3:37am in the morning Order ID number is MGSGQHT26M and receipt number is 130039894814 for $ 43.54 cents but it show up on m

  • Table structure changed in testing system after system refresh.

    Hi Team, Recently we underwent a system refresh in Testing System where the Testing data is filled with Production data. But now we find that in one table some fields which we had deleted they are again found there. The version history of table is al

  • Saving work in LR3.2

    Have only used this program a few times but have not discovered how to save my work when completed. Is it possible to just save a file in some manner that it can be recovered by LR3 or read in another program and/or printed? Thanks Jim

  • Workflow Description Field truncation

    I was wondering if there was a work around to display more than 256 characters in the Approval workflow history list for column description? If, so how do you do it? I deployed a custom Approval workflow using SharePoint Designer 2010 and InfoPath. I