How to put data from database into array

I need to answer hot to put data from database directly into array.
I tried like the code below but the error message said: java.lang.ArrayIndexOutOfBoundsException: 0, and it points to this line: numbers [row][0]= rs.getString("ID");
Hope you can help.
ResultSet rs = stmt.executeQuery(query);
     int row=0;
     String [] [] numbers=new String [row][10];
     // output resultset
     while ( rs.next() )
          numbers [row][0]= rs.getString("ID");
          numbers [row][1]= rs.getString("name");
     row++;
     // close resultset
     rs.close();
thanks,Devi

The exception is been thrown simply because you assigned '0' to the 'row' variable, indicating a zero length of the array. In fact you should assign the row count to it.
After all, don't do that. Make use of the Collection framework and map the ResultSet to a Collection of DTO's.
List<User> users = new ArrayList<User>();
while (resultSet.next()) {
    User user = new User();
    user.setID(resultSet.getString("ID"));
    user.setName(resultSet.getString("name"));
    users.add(user);
}

Similar Messages

  • How to put datas from database in html�s forms?

    Does anyone have any idea how to put datas from the database using JSP???

    One option: put your data into a JavaBean and then put that into the session. You can then access it from your JSP. You can access the properties of the bean using the basic JSP scripting elements, or if you want to get fancy, both JSTL and Struts have a bunch of custom tags for working with JavaBeans.

  • How to Retrieve data from database into another form ?

    Good Day!
    Am currently new at JSP. I've been studying it for awhile and still getting the hang of it. We are working on a project.
    Editing a given data. We have to retrieve the given data and post it to another form "Editing form".
    Since we can retrieve data using JSP but how are we going to post it to another form? I mean how are we going to transfer data from one form to another?
    Can anyone help me with codes please..

    The client is a web browser.
    The client submits a request (click a link, visit a form)
    The server gets to respond to this
    - look at request parameters from the client
    - access database
    - produce resulting html page
    - send page back to client.
    The standard pattern is to retrieve data from the database in java code, and then load that data into a bean.
    You then make that bean available as an attribute
    It is then available for use in your JSP - either <jsp:useBean> tag or using ${ELexpressions}
    All you can pass from the client to the server is request parameters - which are always strings.
    Draw a picture of where the information is, and the information flows. Very rarely does it go directly from one "form" to another.
    Cheers,
    evnafets

  • How to download Data from Database directly into excel

    I have a requirement to download very large quantity of data from database into Excel file.
    But condition is excel file should have only 65,536 rows in a single spread sheet(that's the limit i suppose),if i have more data points(rows) than it should be stored into different spreadsheet.......this continues so there can be many spread sheets in a single excel file.
    Data size can be 1 GB or more.
    Also specific naming conventions need to be followed for giving name to excel as well as different spread sheets in it.
    Please see if someone could help me out.

    Thanks for ur reply,
    But my requirement is to call "download to excel" method,in a java program on click by user for downloading an excel sheet on his machine.
    This is be done as part of a web application which is to be made (so can't open the excel first)

  • How to load data from Quikbooks into PeopleSoft General Ledger module ?

    Folks,
    Hello.
    My client's data is currently stored in Quikbooks.
    After install PeopleSoft FSCM 9.0, I need to load the data from Quickbooks into PeopleSoft General Ledger module. But I don't know how to use PeopleSoft Integration Broker to integrate with Quikbooks.
    Can any folks tell me how to load data from Quikbooks into PeopleSoft General Ledger module ?

    Hi,
    If the data load is one time process, then you can use PL/SQL or datamover to load the data to PeopleSoft application.
    If you want to load the data in real time, then you need to create In-bound and out-bound nodes to perform the transaction.
    Thanks
    Soundappan

  • Script to put Datas from Database to TextInput

    Hello,
    As it is said in the title, I would like to put Datas from Database to Textinput. Here's my application :
    Well, what I want to do is when you click on the lines in the Datagrid, the "Nom Area" is completed by the Name in the Datagrid, the "adresse area" by the adress in the Datagrid ...
    Can someone help me ? please
    Thank you

    Here's my code
    <code>
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:fourD="http://www.4d.com/2007/mxml" layout="absolute"  viewSourceURL="srcview/index.html" backgroundGradientAlphas="[1.0,1.0]" backgroundGradientColors="[#EDE3E3, #555555]" color="#040404" height="899">
    <mx:Script>
    <![CDATA[
    import fourD.sql.*;
    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var _resultSet:SQLResultSet;
    // Initialisation de la connection
    private function connectHandler(event:Event):void
    fourDSQLService.execute("SELECT * FROM clients"); }
    private function resultHandler(event:ResultEvent):void
    if(event.result != null) { _resultSet = event.result as SQLResultSet; } }
    // En cas d'erreur
    private function faultHandler(event:FaultEvent):void
    var zeError:String= "Error #" + event.fault.faultCode;
    // Message d'erreur
    Alert.show(event.fault.faultString,zeError); }
    ]]>
    </mx:Script>
    <!-- Declaration du serveur SQL-->
    <!-- Connection automatique au dŽmarrage de l'application (login/mdp)-->
    <!-- ImplŽmentation des fonctions -->
    <fourD:SQLService id = "fourDSQLService"
    host = "127.0.0.1"
    userName = "sqlUser"
    userPassword="sql"
    autoConnect="true"
    result = "resultHandler(event)"
    fault = "faultHandler(event)"
    connect="connectHandler(event)"
    />
    <!-- Declare the 4D datagrid; It is also possible to use Flex embed datagrid -->
    <!-- Bind datagrid source to SQLresultSet coming from 4D-->
    <fourD:DataGrid id="contacts_dg"
    dataProvider="{_resultSet}" x="10" y="207" width="737" height="397"
    />
    <mx:Button x="588" y="627" label="Ajouter" id="btnAjouter"/>
    <mx:Button x="666" y="627" label="Supprimer" id="btnSupprimer"/>
    <mx:Text x="10" y="10" text="Nom" />
    <mx:Text x="10" y="36" text="Secteur d'activitŽ&#xd;"/>
    <mx:Text x="10" y="62" text="Groupe"/>
    <mx:Text x="10" y="112" text="Responsable commercial"/>
    <mx:Text x="10" y="88" text="Adresse"/>
    <mx:Text x="416" y="88" text="Ville"/>
    <mx:Text x="595" y="88" text="Code Postal"/>
    <mx:Text x="10" y="138" text="Responsable production&#xd;"/>
    <mx:Text x="416" y="112" text="Responsable 3"/>
    <mx:Text x="416" y="138" text="Responsable 4"/>
    <mx:Text x="624" y="10" text="Code"/>
    <mx:RadioButton x="610" y="34" label="Client"/>
    <mx:RadioButton x="675" y="34" label="Prospect"/>
    <mx:TextInput x="48" y="8" width="568" id="nomArea" />
    <mx:TextInput x="117" y="34" width="485"/>
    <mx:TextInput x="666" y="8" width="81"/>
    <mx:TextInput x="675" y="86" width="72"/>
    <mx:TextInput x="63" y="60" width="684"/>
    <mx:ComboBox x="157" y="110" width="251"></mx:ComboBox>
    <mx:ComboBox x="157" y="140" width="251"></mx:ComboBox>
    <mx:ComboBox x="512" y="110" width="235"></mx:ComboBox>
    <mx:ComboBox x="512" y="140" width="235"></mx:ComboBox>
    <mx:Text x="317.5" y="161" text="Liste Clients" fontSize="19"/>
    <mx:TextInput x="63" y="86" width="345"/>
    <mx:TextInput x="452" y="86" width="135"/>
    </mx:Application>
    </code>

  • How to retrive data  from  database views or projection views

    how to retrive data  from  database views or projection views

    Hi chintam,
    1. Very simple
    2. Just like normal select statement.
    3. Select * from VIEWNAME.
    4. (Instead of the tablename, we just have to give the viewname)
    regards,
    amit m.

  • How to save data from form into database

    i nid to save data from form into the new table, @abc.
    got any idea ?
    smtg like oObj = BaseAddOn.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes) this but it is a new object or user data source.
    Thanks

    hi
    i have created UDO i have also done registration  i want to bind item master completely to matrix and then in one column i will set check box to check unchecked and then i want to save it to database
    i have one user defined form and 4 matrix and 4 child tables
    for each matrix i have given 1 form and i have to transfer the data from temp form to main form matrix having large data in matrix on temp form to main form matrix
    to load data on matrix i have used for loop that i want to avoid so how i can bind large data to matrix without for loop
    regards
    amey

  • How to display data from Database individually??? Anyone can help ?

    HI,
    i i had select a row of data from database using ,
    /* Query * From Table RESOURCEORDER where po = selected no and project = selected project */
         public ResultSet getAllData() throws SQLException
         getConnection();
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
         return rs;
    After that , how do i display the data individually ?
    Eg select data is ('projectA','7891203-1', '10-4-2005','lcd',2000,'121-45217-8','electrical','pending','donwong')
    i want to display them individually, like this in a page
    Projectname: /* should display the Project A*/
    P.O no:
    Date:
    Order:
    Cost:
    Acc no:
    Type:
    status:
    Orderedby:
    Can anyone help ? cos i'm new to JSP ......Thanks alot!!!!!
    Regards,
    khim

    I assume PO being a unique key, will always return 1 row from db.
    public String[] getAllData() throws Exception
    getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
    String [] returnValue = new String[9];
    while(rs.next())
    returnValue[1] = rs.getString("colname");
    returnValue[2] = rs.getString("colname");
    ///and so on
    return returnValue;
    }Once you get that you could individually view it by setting a loop to run through the returned array.
    Hope it helps

  • How to retrieve data from database to the structure(complicated)

    Hello everyone:
           I want to retrieve data from database to the structure. but the structure defined like this below:
    TOLERANZOB LIKE QAMV-TOLERANZOB
    TOLERANZOB1 LIKE QAMV-TOLERANZOB
    so how can I retrieve the data from the database ? make sure that the two fields contain data both.
    Thanks in advance .
    Regards
    Nick

    Hi Nick,
    To retreive data for TOLERANZOB from QAMV,
    If you know the key fields then use
    SELECT SINGLE TOLERANZOB FROM QAMV INTO TOLERANZOB WHERE keyfields.
    else, you can use
    SELECT TOLERANZOB FROM QAMV UPTO ONE ROWS INTO TOLERANZOB WHERE....
    Once you retreive the data using the select query, you can check if it is initial and if not move the data from TOLERANZOB to TOLERANZOB1.
    <b>Reward points for helpful answers.</b>
    Best Regards,
    Ram.

  • How to populate data from table into datagrid in form

    hi there. may i know how to populate data from a table into a datagrid? i have created a datagrid in a form using OLE's microsoft datagrid. i'm having problem to populate data from table into the grid. can i know how to do that? thanks

    Not exactly. I want to enter input from form and the user can have all options to choose i.e. HIGH, MEDIUM or so on.
    Suppose, you have option to select HIGH, MEDIUM or LOW and you can see all these options together. You select LOW and when you save, it is saves in the table as a value. So when you view the table again, it will show LOW as active and HIGH and MEDIUM are null.

  • How to fetch data from database in javafx 2.2 table which is editable.

    Dears!
    I want to fetch data from database in javafx 2.2 tableformat with jdbc , which is also editable and i can add more records in this table also.
    Can anybody help me

    I can vaguely recall some sort of JavaFX database connectivity feature, I'm not sure if it's valid anymore.The link is based on JavaFX Composer which only applied to NetBeans 6.9 and JavaFX 1.x (both of which are now dead techs).
    There is a good chance you will have to write your own. There are several blogs describing other peoples' work. You could probably use them as a reference.Here is Narayan's basic [url http://blog.ngopal.com.np/2011/10/19/dyanmic-tableview-data-from-database/] tutorial for displaying data from a database in a TableView, you'll need to look elsewhere for the editing portion.
    The [url http://docs.oracle.com/javafx/2/ui_controls/table-view.htm]JavaFX TableView tutorial gives info about how to handle edits in a TableView, but you will need to tie the updates back to the database yourself.
    It is possible that [url http://www.javafxdata.org/]DataFX may provide some facilities to help support you.

  • How to extract data from database to XSLT?

    I want to generate a report by XSLT, but the data is extracted from the database. I will use Access/SQL server for my database. Can i write SQL in XSLT to extract data from database? Have any sample code or reference website to show how it work?
    THX

    for example: "SELECT code, name FROM TABLE FOR XML RAW"
    String xml = null;
    if(rs.next()){
      xml = rs.getString(1);
    }You will get xml string something like this:
    <row empID="1234"/><row empID="1235"/>
    You can construct a DOM using this xml data and operate on it.
    However you may explore more on resulting xml format.
    A different SQL Query (rather than using XML RAW) may give output in a more desired format.

  • Help , How to get data from database using recordset with UI API

    I want to get a data from database
    when I want to create recordset i notice that UI API didn't has record set
    so I created recordset using DI API (SAPbobscom.recordset and SAPbobscom.company)
    ======================================================
    Dim oCompanyUI As SAPbouiCOM.Company <<UI API
    Dim oRecSet As New SAPbobsCOM.Recordset << DI API
    Dim oCompanyDI As New SAPbobsCOM.Company << DI API
    '=====================================================
    oCompanyDI.Connect
    Set oRecSet = oCompanyDI.GetBusinessObject(BoRecordset)
    oRecSet.DoQuery ("SELECT T0.CardCode, T0.CardName FROM OCRD T0")
    SBO_Application.MessageBox oRecSet.Fields.Item(1).Value
    ======================================================
    but I got an error it said "you are not connected to company"
    I'm really don't have an idea about how to get a data from using UI API (exp I want to get a date or costumer code)
    can someone help me please, I really need it
    Thanks

    you need a single sign on
            Dim oDICompany As SAPbobsCOM.Company
            Dim sCookie As String
            Dim sConnStr As String
            Dim ret As Integer
            oDICompany = New SAPbobsCOM.Company
            sCookie = oDICompany.GetContextCookie
            sConnStr = SBO_Application.Company.GetConnectionContext(sCookie)
            If oDICompany.Connected Then
                oDICompany.Disconnect()
            End If
            ret = oDICompany.SetSboLoginContext(sConnStr)
            If Not ret = 0 Then
                SBO_Application.MessageBox("set Login Context failed!")
                Exit Sub
            End If
            ret = oDICompany.Connect()
            If Not ret = 0 Then
                SBO_Application.MessageBox("Company Connect failed!")
            End If

  • Oracle form: how to retrieve data from database to pop list

    I have problem in retrieving data from database to item list in
    oracle forms.
    Can anyone help me.
    thanks.

    The next is an example but you can find this information in
    Forms Help:
    DECLARE
         G_DESCS RECORDGROUP;
         ERRCODE NUMBER;
         rg_id RECORDGROUP;
         rg_name VARCHAR2(40) := 'Descripciones';
    BEGIN
         rg_id := FIND_GROUP(rg_name);
         IF Id_Null(rg_id) THEN
         G_DESCS := Create_Group_From_Query (rg_name, 'SELECT
    DESCRIPCION DESCRIPCION, DESCRIPCION DESC2 FROM FORMAS_PAGO);
         ERRCODE := POPULATE_GROUP(G_DESCS);
         POPULATE_LIST('FORMAS_PAGO.CMBDESCRIPCION',G_DESCS);
         END IF;
    END;
    Saludos.
    Mauricio.

Maybe you are looking for