Click here to Skip to main content
15,614,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am learning gui development in java. My program is to connect to a DB and preform basic operation like add , delete , and show.
My problem is that I cannot display all the element(string name) in text area . It works when put it into the output field but does not work in the text area. How can I fix it.
Here is my code to display the data from DB to text area.
<blockquote class="quote"><div class="op">Quote:</div>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)                                         
        try {
            String sqlquery1 = "SELECT * FROM GUI_TEST.NAME";

            smt = con.createStatement();

            ResultSet rs1 = smt.executeQuery(sqlquery1);

            while ( {
                String dname = rs1.getString("NAME");
                jTextArea1.setText(dname); //Doesnt work
                System.out.println("Name is "+dname); //Works fine
        } catch (SQLException s) {

What I have tried:

As I have stated in the detail. That is the code that I used to display the Name elements from data base to the text area.
Mohibur Rashid 13-May-16 4:22am    
try append function instead of setText
Member 12491145 13-May-16 9:31am    
Thank you for the reply but it gives me and exception error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gui_test.main_from.jButton2ActionPerformed(
at gui_test.main_from.access$200(
at gui_test.main_from$3.actionPerformed(
at javax.swing.AbstractButton.fireActionPerformed(
at javax.swing.AbstractButton$Handler.actionPerformed(
at javax.swing.DefaultButtonModel.fireActionPerformed(
at javax.swing.DefaultButtonModel.setPressed(
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
at java.awt.Component.processMouseEvent(
at javax.swing.JComponent.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(
at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEventImpl(
at java.awt.EventQueue.access$500(
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(
Member 12491145 13-May-16 9:57am    
I re implemented it and append worked great. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900