Bind a resultSet to a Database

I know that there is info on this somewere in the tutorials, but I can't find it. Im looking for info on how to bind a resultSet to a Database, so that changes in the resultset is reflected in the Database...
All help appriciated
- Karl XII

If im not mistaken, once you execute a query with the proper connection params, the result is *always bound to the database.                                                                                                                                                                                                                                                            

Similar Messages

  • Using functions in Resultset while getting database data.

    Well I'm trying to reset my resultset and it doesn't work.
    Frist I extract data from it. Then I want to start to get other data from hte beginning again. Is this not possible. Can I just get thew data once.
    I'm working with an access database and developping at Oracle 10g
    <select name="kundKontakter" size="1" >          
               <%         
                do{
                 String OID_kont =resultatKontaktNamn.getString("OID_kont");
                 String namnKontakt = resultatKontaktNamn.getString("fKontaktNamn");
                <option value="<%=OID_kont%>" SELECTED><%=namnKontakt%>
                </option>
              <%
                }while(resultatKontaktNamn.next()); %>         
                </select>
                </td>
            </tr>
            <%resultatKontaktNamn.first();%>
            <tr><td>telefon</td>
            <td><input type="text" name="tel" size="40">
             <%=resultatKontaktNamn.getString("tel")%></td></tr>
            </tr>

    No, normally result sets are read-once. If you need to get at data multiple times, you should read it into an an-memory table structure, like a List of Maps (or a List of objects that represent a row on the DB...)
    So, for example, make a class:
    public class Kontakt {
      private String namn, OID, tel;
      public Kontakt(String id, String n, String t) {
        namn = n; OID = id; telefon = t;
      public String getNamn() { return namn; }
      public String getOID() { return OID; }
      public String getTelefon() { return telefon; }
    }Then when you access the database you fill up a java.util.List with a bunch of instances of this class...
      java.util.List kontaktList = new java.util.ArrayList();
      while(resultatKontaktNamn.next()) {
        String OID_kont =resultatKontaktNamn.getString("OID_kont");
        String namnKontakt = resultatKontaktNamn.getString("fKontaktNamn");
        String telefonKontakt = resultatKontaktNamn.getString("tel");
        Kontakt k = new Kontakt(OID_kont, namnKontakt, telKontakt);
        kontaktList.add(k);
      }That all done before you try any display.
    Then, your JSP output will look like this:
        <select name="kundKontakter" size="1">
        <%
          for (java.util.Iterator i = kontaktList.iterator(); i.hasNext(); ) {
            Kontakt kont = (Kontakt)i.next();
        %>
            <option value="<%= kont.getOID()%>" selected="selected"><%= kont.getNamn()%></option>
        <%
        %>
        </select>
      </td>
    </tr>
    <tr>
      <td>telefon</td>
      <td><input type="text" name="tel" size="40">
        <%= ((Kontakt)kontaktList.get(0)).getTelefon() %></input>
      </td>
    </tr>

  • How can I set the data binding between Web Dynpro & Database table

    Dear friend,
    I am a beginner of Web Dynpro. I want to develop my simple project like these:
    1. Create my own database table via Dictionary Project such as TAB_USER and have 3 fields: USER_ID, USER_NAME, USER_POSITION and I have already deployed & archived it.
    2. Create my own Web Dynpro Project, and create the input fields as User ID, User name, User position and icon 'Save' on the selection screen and I have deployed it already.
    For the process, I want to input data at the screen and save the data in the table, please give me the guide line like these:
    1. How can I set the data binding between Web Dynpro and Database table ?
    2.  Are there any nescessary steps that I will concern for this case?
    Sorry if my question is simple, I had try  to find solution myself, but it not found
    Thanks in advances,
    SeMs

    Hi,
    You can write your own connection class for establishing the connection with DB.
    Ex:
    public class  ConnectionClass {
    static Connection con = null;
    public static Connection getConnection() {
    try{
    Context ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("jdbc/TSPAGE");
    con = ds.getConnection();
    return con;
    }catch(Exception e){
    return null;
    You can place the above class file in src folder and you can use this class in webdynpro.
    You can have another UserInfo class for reading and writing the data into the DB .
    Regards, Anilkumar
    PS : Refer
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/java/simple java bean generator for database.pdf
    Message was edited by: Anilkumar Vippagunta

  • How to bind "Image Field" object on a database

    Hi to all
    I inserted into a dynamic PDF (Livecycle ES3 trial) an image field, but I don't understand how I can to bind a JPG into a database.
    In (F5) preview... I'm able to open a image file on filesystem and visualize it on PDF form... but then? How to bind on database?
    In my several tentatives I'm using a MS Access 2010 database table, where I defined a OLE object... but doesn't work.
    Thank you at all.
    visert

    Hi,
    I have not tried to do this, but this document provides some instructions.
    http://partners.adobe.com/public/developer/en/livecycle/lc_designer_XML_schemas.pdfhttp://partners.adobe.com/public/developer/en/livecycle/lc_designer_XML_schemas.pdf
    Hope it helps
    Bruce

  • UIDataTable with ResultSet ...?

    Can anybody give me an example of how to display the data from a RasultSet into a UIDataTable ?
    I have already tried one but it is not working.
    In one of the example i have following tag listing....
    <h:dataTable value="#{catalog.resultSet1}" var="catalogItem" >
    <h:column>
    <f:facet name="header">
    <h:outputText value="id"/>
    </f:facet>
    <h:outputText value="#{catalogItem.id}"/>
    </h:column>
    <h:dataTable>
    In my bean i have
    .....getCatalogItems(){
    Class.forName("org.postgresql.Driver");
    Connection db = DriverManager.getConnection(dbURL, username, password);
    Statement stmt = db.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    resultSet1 = stmt.executeQuery("SELECT * from choice");
    public void setCatalogItems(){
    System.out.println("setCatalogItems called");
    public void setId(int id){
    this.id = id;
    public int getId(){
    return this.getId();
    I don't know if it is right, but i have decalared "id" as a field in a backing bean OR
    are they column names of the underlying table whose data is returned by the ResultSet ?
    I would also like to know if anyone is having an example successfully running which binds a UIDataTable with a ResultSet !

    create-database.sql
    create table CatalogItem (
    id int unsigned auto_increment,
    product_id int not null,
    unitPrice numeric(10,2),
    unitCost numeric(10,2),
    primary key(id)
    supplyStore.jsp
    <h:dataTable value="#{catalog.catalogItems}" var="catalogItem" styleClass="catalogItems" headerClass="catalogHeader" columnClasses="id,amount">
         <h:column>
              <f:facet name="header">
                   <h:outputText value="id"/>
              </f:facet>
              <h:outputText value="#{catalogItem.id}"/>
         </h:column>
         <h:column>
              <f:facet name="header">
                   <h:outputText value="price"/>
              </f:facet>
              <h:outputText value="#{catalogItem.unitPrice}"/>
         </h:column>
    </h:dataTable>
    DataAccess.java
    public DataAccess() throws Exception {
    try {
    InitialContext ic = new InitialContext();
    Context envCtx = (Context) ic.lookup("java:comp/env");
    DataSource ds = (DataSource)envCtx.lookup("jdbc/SupplyStore");
    con = ds.getConnection();
    } catch (Exception ex) {
    throw new Exception("Couldn't open connection to database: " + ex.getMessage());
    public void remove() {
    try {
    con.close();
    } catch (SQLException ex) {
    System.out.println(ex.getMessage());
    private final static String SELECT_CATALOGITEM_QUERY =
    "select id, product_id, unitPrice, unitCost from CatalogItem";
    public ResultSet getCatalogItems() throws SQLException {
    PreparedStatement st = con.prepareStatement(SELECT_CATALOGITEM_QUERY);
    return st.executeQuery();
    Catalog.java
    public ResultSet getCatalogItems throws SQLException {
    if (catalogItems == null) {
    catalogItems = dataAccess.getCatalogItems();
    return catalogItems;
    I don't know if it is right, but i have decalared "id" as a field in a backing bean OR You don't need declare "id".
    are they column names of the underlying table whose data is returned by the ResultSet ?Yes
    I would also like to know if anyone is having an example successfully running which binds a UIDataTable >with a ResultSet !I have working example with ResultSet and RowSet (MyCashedRowSet, JdbcRowSetImpl).
    Just let me know if you need more information.
    Best regards,
    Vladimir Perlov

  • From Database into JTable

    Hi!
    I have a ResultSet from a database query (select * from table) and I plan to turn it into a Object[][] in order to satisfy one of the DefaultTableModel's constructor ("DefaultTableModel(Object[][] data, Object[] columnNames)") and place it in a JTable - how do I go about in doing this.
    I tried this:
    myJTable.setModel(new DefaultTableModel(getData(rs),columnNames));
    private Object getData(ResultSet rs){
    java.util.ArrayList<Object[]> mySets = new java.util.ArrayList<Object[]>();
    try{
    while(rs.next()){
    Object[] row = {
    rs.getString("column1"), rs.getString("column2"), new Boolean(false)
    ResultSets.add(row);
    catch(Exception e){
    e.printStackTrace();
    return mySets;
    But got this error when I compiled:
    cannot find symbol
    symbol : constructor DefaultTableModel(java.lang.Object,java.lang.String[])
    location: class javax.swing.table.DefaultTableModel
    new DefaultTableModel(
    1 error
    BUILD FAILED (total time: 0 seconds)
    I'm trying to do this because I would want to have my JTable to have a checkbox in it like what's shown in the Java tutorial's SimpleTableDemo.java.
    Basically, am getting data directly from the database - those that are set to 1 is enabled and 0 to disabled, then represent those as check boxes in the JTable.
    Thank you so much for your help!

    Thanks calvino_ind!
    I've managed to get your suggestion to work:
                while(rs.next()){
                    for(int i = 0; i < row; i++){          
                        for(int j = 0; j < col; j++){
                            obj[i][j] = rs.getObject(j+1);
                        rs.next();
                }Issues:
    I had to define the number of rows in order to initialize the Object's size:
                Object[][] obj = new Object[number of rows][number of columns];*column size can be retrieved from what's shown in previous post.
    To get the number of rows I had to do this:
                while(rs.next()){ row++; }But in doing so, the cursor moves to the last row of the ResultSet. To move it back I had to execute this:
                rs.beforeFirst();Here's the whole section of the code that's been my concern:
        private Object[][] getData(ResultSet rs){
            Object[][] obj = null;
            int row = 0;
            int col = 0;
            ResultSetMetaData rsmd;
            try{
                rsmd = rs.getMetaData();
                while(rs.next()){ row++; }
                System.out.println(rs.getFetchSize());
                col = rsmd.getColumnCount();
                obj = new Object[row][col];
                rs.beforeFirst();
                while(rs.next()){
                    for(int i = 0; i < row; i++){          
                        for(int j = 0; j < col; j++){
                            obj[i][j] = rs.getObject(j+1);
                        rs.next();
            }catch(Exception e){
                e.printStackTrace();
            return obj;
        }Now I did a little bit of fiddling around the forums, and came across a discussion that's it's not advisable to get the row count (second post of this link: http://forum.java.sun.com/thread.jspa?threadID=683676&messageID=3982010).
    Anyone care to shed some more light into this?
    Thanks!

  • Mapping ResultSet to Context and vice versa

    Hi,
    We've been pondering the usage of SQL ResultSet (java.sql.ResultSet) and the context.
    When creating database applications we have to get the data from database to a ResultSet and copy the data to the context to be able to use it. Then if we make changes to the data in the context, and have the same changes in the database, we have to create SQL update clauses for the data in the context and execute them. With ResultSet it would be just:
    rs.updateString("NAME", "AINSWORTH"); // updates the name
    rs.updateRow(); // updates the row in the datasource
    We would like to use ResultSets for the data behind controls (tables etc.) to be able to update the resultset and the database without having to write SQL update, insert, delete etc. clauses.
    Is this possible ? If it is, how ? If it is not, why ?
    Any insight or suggestions are greatly appreciated.
    Kind Regards,
    Jari Pakarinen

    Thanks for the reply,
    Web service would just add complexity, as we are aiming for simplicity. Also we would like to lessen the amount of boilerplate code to do this. Now we have to create SQL clauses for everything we do with the database. And this for every application we code.
    If we could use ResultSet instead of Context or somehow map Context and ResultSet dynamically as the data source for the controls we'd be all set.
    We would like to just load the data into a ResultSet, do modifications to it WITHOUT SQL (with e.g. WebDynPro table) and commit the modifications WITHOUT SQL back to the database. Only SQL needed would be the one that loads the ResultSet in the first place.
    Regards,
    Jari
    Message was edited by: Jari Pakarinen

  • Multi-Database Access

    I am attempting to access four databases with identical structure/tables containing information about data loading
    errors. I wrote a query providing a list of error ids with a count of each, which currently must be run in each database
    separately. A DBA suggested I write a PL/SQL anonymous block procedure with a FOR loop to combine the resultset
    from each database into an overall resultset, but it seems that connectivity would be an issue if I used conventional
    tools such as SQL*Plus or others which require connection to a database before execution of SQL or PL/SQL.
    Is there any sample code or templates which might provide clues on how to implement this requirement?
    Barry

    Have you thought about creating database links in one of the databases to point to the appropriate table(s) in the other three?
    You could then use a UNION to get all the results into a single query.

  • ResultSet "hangs" after every 10 records

    Hi
    Please could you somebody help me.
    I have extracted a ResultSet from a database which contains between 100 and 200 records (5 field each).
    If I call rset.next(), printing a count after each call my program hangs for about 2 minutes after every 10 records.
    For example:
    int count = 0;
    while(rset.next()) {
    System.out.println("" + ++count);
    Prints:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Waits here for two minutes and then carries on
    11
    20
    Waits again for 2 minutes etc.
    Has anyone had this problem or does anyone know how to fix it?
    FYI: prstat reports tiny CPU and memory usage so the hardware is not responsible.
    Thanks a lot in advance

    Hi All
    It must be network - setFetchSize is unsupported in both Statement and ResultSet in the driver set I am using.
    It is running through a 10baseT switch at the moment which may be the problem so I will stick it on the backbone and try again.
    Thanks again for your help.

  • Displaying data from database using Repeater

    Hi,
    I have created a database with 3 column in a table.Where column 1 is username and column 2 is Report name.
    Column 1 has 2 user :-
    user1-----> ABC
    user2-----> PQR. So if i select ABC i am getting 2 records from Report based on ABC and if i select PQR i get 1 record from Report based on PQR.Till here i have done
    Now I am using repeater control and binding the data from the database.but the problem is I want hyperlink on the data which is populating.Since i am using repeater,i am able to fetch 2 records for Report.I want hyperlink on it so i am using anchor tag with
    href,Now both the records are redirecting to the same page.I want each record should redirect to different page.Please help me if any one know about these.
    Thansk Regards,
    Simanchal

    Hi,
    Base on your description here:
    "I want hyperlink on it so i am using anchor tag with href,Now both the records are redirecting to the same page"
    I agree with Bob you have to consult this issue on this forum:
    http://forums.asp.net/24.aspx/1?Web+Forms+Data+Controls
    Regards,
    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • JTable binding using JPA

    Hi,
    I'm having a database table containing blob column that contains image for each row. Also I'm having a JTable in front end to display existing records of database using Toplink(JPA).
    My requirement is as follows
    1) code snippet to bind & persist the image into database column which was selected from frontend (I'm displaying the image on jlabel using filechooser).
    2) retrieving the saved image on a JLabel when ever I select a row in front end JTable.
    I hope you understood my intend.
    looking forward for your response.
    Regards,
    Chandu

    Hi Chandu,
    If you are using JDeveloper for generating the bindings for model persist and binding code will be generated by JDeveloper.
    TopLink/JPA wizard will identify the type of column and generate Entities.When you create a SessionEJB and generate datacontrol,persist operation will bind the input data(in this case image) to a table column.
    Regards,
    Vinay

  • What's disadvantages when using bind variables always in java?

    Hello everyone .. Could someone tell me what's the disadvantage when using bind variable in java ? I heard it somecases since before.. Thanks in advance!

    99% of the time, you should be using bind variables. If you have columns which are highly skewed, however, you may want to consider using literals (assuming CURSOR_SHARING=EXACT), since that may allow the CBO to make a better decision.
    If you have an orders table, for example, you may have a status column that specifies whether the order is complete, in transit, or new. If you've been running for a while, 99% of your orders will be complete, so
    SELECT COUNT(*)
      FROM orders
    WHERE status = :1should do a full table scan if you specify 'COMPLETE'. If you passed in 'IN TRANSIT', though, an index scan might be more appropriate. If you want to pass in different values and get different query plans, you need to use literals. 99% of the time, though, you want the same plan, so you want to use bind variables.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Runing a database outside of an IDE

    Hello,
    I am wondering if anyone could help me;
    I am creating a java database application in netbeans 6.1 (with JDK 6). I can get the application along with the database to compile and run fine as long as I have started a connection to the database server in the netbeans runtime window. However I want to be able to run the application without having to connect to the database server inside the IDE i.e after the application has been 'built'. I have no set username and password, and have binded GUI elements to a database using the new database application shell in Netbeans 6.1
    If anyone could offer me advice on how to have a working connection outside the IDE it would be appreciated greatly.

    SilentScorn wrote:
    Hello,
    I am wondering if anyone could help me;
    I am creating a java database application in netbeans 6.1 (with JDK 6). I can get the application along with the database to compile and run fine as long as I have started a connection to the database server in the netbeans runtime window. However I want to be able to run the application without having to connect to the database server inside the IDE i.e after the application has been 'built'. I have no set username and password, and have binded GUI elements to a database using the new database application shell in Netbeans 6.1
    If anyone could offer me advice on how to have a working connection outside the IDE it would be appreciated greatly.I'll assume you mean Derby.
    I think you'll need to figure out how to start and run Derby in server mode. You'll connect using a URL that includes the name of the host server, port, and database you wish to connect to. You'll still use JDBC, of course.
    Sorry I'm not much help with the details. I don't use Derby myself, but I have run HSQLDB in both in-memory and server mode. I'm imagining that Derby is similar.
    %

  • Lost Milliseconds when getting timestamp from database

    I store a timestamp in DB2 by formatting the current timestamp using the following format mask :
    "yyyy-MM-dd-H.mm.ss.SSS". I query the database and the milliseconds are there. When I retrieve a resultset from the database and get the column using rs.getTimestamp(), I reformat it using the same formatting mask and LOSE all the milliseconds. I believe I'm losing the milliseconds when I execute the getTimestamp() method. What do I have to do to get the entire timestamp from the database, including the milliseconds?

    I pulled this quote directly out of the jdk docs:
    "If a time value that includes the fractional seconds is desired, you must convert nanos to milliseconds (nanos/1000000)"
    the timestamp doesn't actually have a millisecond value. You can get it by calling the getNanos() function and /1000000.
    you might be losing the millisecond value because there isn't a millisecond value, only nanoseconds.
    good luck
    Jamie

  • Populating JSF ListBox from DataBase

    Hi,
    im new to JSF and i have a problem populating Listboxes with database values.
    i have 3 listboxes and the 3 are populated from tables in my database.
    I would like to filter the returned(from database) values in the 2nd listbox depending on the value selected in the 1st listox.
    I dont know how to do this.
    BTW i'm usis Ibatis Abator to map the database.
    tnx

    Here is what I think you are wanting to do:
    1. Have the list box show values from a database table.
    2. Have the user make selections. Should the user return to that page later in the session, have the previous selection still selected.
    Normally, you would bind the listbox to the database table, as is shown in http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/databoundcomponents.html. The only reason I can think of for not binding directly to the database table is if there is a possiblity that the database table can change (additions, updates, deletes) during the user's session.
    Are you able to emulate the above tutorial using the Postgress database? It might be good to pinpoint whether the problem is with the Postgress driver or with the code you are writing.
    By the way, if you use a data provider to access the database, as shown in the tutorial, here is how you iterate through the data
            try {
                myDataProvider.cursorFirst();
                do {
                    [build your options list here]
                } while (myDataProvider.cursorNext());
            } catch (Exception ex) {
                error("put your message here" +
                        ex.getMessage());
                log("put your message here: " +
                        ex.getMessage(), ex);
            }You are correct to bind the selected property to a session bean property in order to perserve the user selecitons through the user's s session.

Maybe you are looking for

  • RCA to Firewire converter?

    I'm just starting to get into real editing (FC Exp rather than iMovie) and I realize that people may give me video in fromat other than my mini DV. Am I right in thinking I need a converter (RCA to Firewire?) to get video off their camcorder onto my

  • Itunes videos not playing on macbook pro

    itunes videos and movie trailers are not playing on my macbook pro.

  • Drop-down list in editable ALV

    Hello all, Does anyone know how to display the values instead of the internal values when using the alias table to specify a drop-down list in an editable ALV grid ? Apparently the BC_ALV* examples have the same problem. thx Pieter

  • Moving from ABAP to ABAP oo

    We are currently running on a 4.0 system, but are preparing for an upgrade to ERP '05. I have looked at OO and have collected a few questions. 1.     A simple ABAP report today in 4.0 looks like this : Selection-screen Start-of-selection Perform read

  • How do I create a table with header cell tags for screen readers in indesign cc 2014?

    In order to create a table that's readable for screen readers, I need to give the cols and row values like headers. This way the screen reader should be able to understand what the value in it's corresponding cell is. But... how do do this?