How to store data from database & display

I am trying to connect to the database Northwind through sqlserver.
My code is as follows
public String data() {
        try {
            System.out.println("Control is in fieldlist.data::::::::");
          Context context = new InitialContext();
          Map sessionMap=FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
          FieldList flist=(FieldList)sessionMap.get("fieldList");
          DataSource dataSource =
            (DataSource)context.lookup("java:comp/env/jdbc/Northwind");
            System.out.println("dataSource::::::::"+dataSource.toString());
          Connection connection = dataSource.getConnection();
          System.out.println("connection::::::::"+connection);
          Statement statement = connection.createStatement();
          String query = generateQuery1();
          System.out.println("In data ::query::::::::"+query);
/* Problem Starts here */
         ResultSet resultSet = statement.executeQuery(query);
Result result=ResultSupport.toResult(resultSet);
System.out.println("result::::::::::::"+result);        
          return "success1";
        } catch(Exception e)
            System.out.println("Connection error "+e);
            return(null);
  }So on calling the method data() the above code is getting executed.
Here I am also able to print the value of result which comes in hexadecimal format.
But I am not able to display the data when I run the application.
May I know what I am doing wrong here.

Thanks.
But I want to know what is the method to extract values from ResultSet
while(resultSet.next())
                  //what should be the method here.
          }

Similar Messages

  • How to store data from textfile to vector and delete a selected row.

    Can someone teach me how to store data from textfile to vector and delete a selected row. And after deleting, i want to write the changes in my textfile.
    Do someone has an idea? :)

    nemesisjava wrote:
    Can someone teach me how to store data from textfile to vector and delete a selected row. And after deleting, i want to write the changes in my textfile.
    Do someone has an idea? :)What's the problem? What have you done so far? What failed?
    What you described should be pretty easy to do.

  • 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 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 store data from Host.vi in cRIO-9074

    TejasKumar Patel
    I implemented a advance Measurement and Control system using cRIO-9074
    with c-Series I/O cards( NI 9217, 9411, 9264)
    I have some questions about it,
    (1)- Data rate from FPGA targate to host vi is too low. how can I increase
    it, when I run my host VI, sometimes all temperature sensor update at
    same time and sometimes one by one, can you please give me some hint, how
    can I correct it, I used two FIFOs for NI-9411 digital pulses, I put all
    Digital input and all analog output and input in a seperate while loop in
    FPGA targate VI.
    (2)- I have to write that data to analyse for further result. I tried all
    possible way to write data including wite to spreadsheet.vi, write to
    text.vi, Data storage.vi, Write to measurement.vi. All this VI work
    efficientlywhen it run individualy, But when I connect this VI to
    writedata from FPGA host VI. than it always give empty file.
    I saw your post in NI discussion forum about how to write data from
    Host.vi, But still I am confuse that how can I creat a protocol between
    host VI and Fpga target vi. to write the data in a file. I have nearabout
    38 channel to write data.
    (3)- I have to measure time difference between two digital pulses, to find
    a flow rate. I am using counter for it with risisng edge shot.vi, but when
    i get a timestemp when there is risisng edge for the second rising edge
    how can I get timestemp. Its like i have to measure time between two
    pulses, I triend waveform measurement.vi to find cycle period. but it not
    worked. any other was to measure it.
    I am stuck in this question since from last one month. I already followed
    NI-discussion forum solution but it doesnt work. I think the way I applied
    is may be wrong. 
    Looking forward to hear from you soon.
    Plese send an additional email copy to [email protected]
    Thank you and Best Regards, 

    Thanks Joseph for your support,
    1-      If I count the ticks between the pulses it always seems different ….because this method I already tried, but it does not work,  like some times it shows 9099 tick and at the second pulse it shows like some more or less ticks not the same ticks every time. To complete my project, the biggest problem is the data storage.
    2-      As you gives the solution in NI forum, “low level file I/O Vis such as Write to text file” FPGA target not support this VI. And mainly I want to write data from HOST.vi, because I am process those data …and I need to store it. For to figure out my result.
    3-      If I use “Write to text file. VI (Sub-VI ) to FPGA.vi, it not support because it support string data and I have FIXpoint data. And can you explain me what is low level file IO, and how can I use in fpga.vi??
    4-      Yes, for my project time stamp it really necessary, for data analysis.
    5-      I need the time stamp to find out what was the system response at the time.  As our project based on weather temperature, I need time stamp.
    Waiting for your reply,
    Thanks and Regards,
    Patel

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

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

  • 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

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

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

  • 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 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);
    }

  • How to store data into database by reading sql statements from text file

    how to write java program for storing data into database by reading sql statements from text file

    Step 1: Create a property file to add various queries.
    Step 2: Read the properties file using ResourceBundle
    Step 3: Use the jdbc to execute the query read from the property file.
    So in future if you need to change query no need do any modifications in java program. But depends on how you use the property file.

  • How to sort data from database and display in combobox in required order

    Hi evrybody, it makes me sick i need to get data form database and fill combobox in required order (last item added to database - last firstName) actualy i already did that, but i'm useing DefaultComboBoxModel and all records are sorted in alphabetical order. Thanks very much for any help

    The items in the JComboBox are displayed in the order in which you add them to the combo box. Use an order by clause in your SQL statement.
    Don't [url http://forum.java.sun.com/thread.jsp?forum=54&thread=516608]crosspost.

  • How to get data from database to JComboBox

    hi
    i am trying to get data which is in database. here the problem is i am getting only one row in the JcomboBox
    i want all data just like list. i dont know how to get that . below is the code plz any one help me....
    import javax.swing.*;
    import javax.swing.JList.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.String.*;
    import java.lang.Integer.*;
    import java.sql.*;
    public class customer_code extends JFrame implements ActionListener
    Container c=getContentPane();
    JLabel customer_code=new JLabel("Customer Code and Name");
    customer_code()
    super("Customer Details");
    setSize(300,250);
    setVisible(true);
    setLayout(null);
    setLocation(430,310);
    Font f=new Font("SansSerif",1,16);
    Font f1=new Font("SansSerif",0,14);
    customer_code.setBounds(10,20,250,30);
    add(customer_code);
    customer_code.setFont(f);
    ResultSet rs=null;
    String j=null,k=null;
    try
    System.out.println("MySQL Connect Example.");
    Statement st=null;
    Connection con=null;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:project","vikky","vishu");
    System.out.println("Connected to the database");
    st=con.createStatement();
    rs=st.executeQuery(" select code as c,Customer_name as n from customer_details ");
    while(rs.next())
    j=rs.getString("c");
    k=rs.getString("n");
    System.out.println(j);
    System.out.println(k);
    String[] names = new String[] {j,k};
    JComboBox comboBox = new JComboBox(names);
    add(comboBox);
    comboBox.setBounds(25,60,250,50);
    comboBox.setFont(f);
    comboBox.addActionListener(this);
    comboBox.setMaximumRowCount(10);
    con.close();
    System.out.println("Disconnected from database");
    catch (Exception e)
    e.printStackTrace();
    public void actionPerformed(ActionEvent event)
    if ("comboBoxChanged".equals(event.getActionCommand()))
    System.out.println("User has selected an item from the combo box.");
    JComboBox comboBox = (JComboBox) event.getSource();
    if(comboBox.getSelectedItem().equals("None"))
    public static void main(String agr[])
    customer_code cd=new customer_code();
    }

    r035198x wrote:
    Also separate that database code from interface display code.
    You should never access the database on the EDT.
    See [Doing Swing Right|http://bytes.com/topic/java/insights/853297-doing-swing-right] for more details.
    Yes! By the time you are working with Swing and JDBC you should already know how to structure code. If not, then you are not ready for these topics and you've jumped the gun.

Maybe you are looking for

  • Error while importing a new CERT in oracle 10G B2B

    Hi All, I am trying to upload a new certificate in 10 G B2B server, its not updating a certificate, I am facing the below error while importing Error An error occurred when updating the certificate. Error -: AIP-16001: The model validation engine fai

  • Planned revenue from Sales document

    HI, We are using Assembly processing where the Project is triggerred thru sales order.The planned revenue from the sales order can be seen in CNS41. Apart from this I am creating some other sales order which I assign manually to the same project but

  • User Customized Oracle R graphs in OBI

    Hi, I have created anonymous block in database as below: begin sys.rqScriptCreate('RandomRedDots3', 'function(n){ plot( 1:n, rnorm(n), pch = 21, bg = "red", cex = 2 ) end; In OBI11.1.1.7 physical layer, created a view as below: select id, image from

  • Help: can't seem to open my iphoto library

    it's a large file sitting on a external hard drive renamed the hard disk (it had a long name and I have a few drives now) but then iphoto said it couldn't find the library the files are still there (I right clicked and all seems good) but I can't see

  • Can I cancel a subscription

    I'm a dumb blonde, just paid for a online number which I don't need ( I didn't read the info first) can I cancel it and have the money paid back into my skype credit? What I really need is a skype to go number