Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:51:17+00:00 2026-06-12T09:51:17+00:00

Hi Guys I have a Swing Application that is connected to an oracle database,

  • 0

Hi Guys I have a Swing Application that is connected to an oracle database, I want it such that Once I type a Value into the JTextField, the other JTextfields on the JFrame are loaded with subsequent data from the database but I do not seem to achieve this. I have tried the Following code but it fetched nothing.

txtNo.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent ke) {
            Connection conn = null;
            try{
                Class.forName("oracle.jdbc.driver.OracleDriver");

        conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "Username", "Password");
        Statement st = conn.createStatement();
        String load = "Select * from Store_info_table where PART_NUMBER = '" + txtNo.getText() + "'";
        ResultSet rs = st.executeQuery(load);
        while(rs.next()){
            txtName.setText(rs.getString("SPARE_DESC"));
        }
            }catch(Exception ae){

            }
        }
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:51:18+00:00Added an answer on June 12, 2026 at 9:51 am

    Do you know if you’re database connection is working? For example, can you run the database portion outside of the listener and it works?

    If so, I would suggest using ActionListeneror a FocusListener instead. KeyListeners (while sometimes necessary) are generally clumsy – there’s usually a better approach (see Java Swing: Using ActionMap for and explaination):

    import java.awt.event.*;
    import javax.swing.*;
    
    public class Example extends Box{
    
        JLabel txtName = new JLabel("Nothing Entered");
    
        public temp(){
            super(BoxLayout.Y_AXIS);
            // Add FocusListener to first field
            final JTextField txtNo = new JTextField(20);
            txtNo.addFocusListener(new CustomFocusListener(txtNo));
            add(txtNo);
    
            // Add TextListener to first field
            final JTextField txtNo2 = new JTextField(20);
            txtNo2.addFocusListener(new CustomFocusListener(txtNo2));
            add(txtNo2);
    
            // Add TextListener to first field
            final JTextField txtNo3 = new JTextField(20);
            txtNo3.addFocusListener(new CustomFocusListener(txtNo3));
            add(txtNo3);
    
            add(new JButton("Do Something"));
    
            add(txtName);
    
        }
    
    
        public static void main(String[] args){
            final JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Example());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    
        /**
         * Your custom focust listener that does all your SQL Work
         */
        public class CustomFocusListener extends FocusAdapter{
            JTextField field;
    
            public CustomFocusListener(JTextField field){
                this.field = field;
            }
    
            @Override
            public void focusLost(FocusEvent e) {
                //Assuming your database connection works, this gives you an example to follow
                txtName.setText(field.getText());
                /*Connection conn = null;
                try{
                    Class.forName("oracle.jdbc.driver.OracleDriver");
    
                    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "Username", "Password");
                    Statement st = conn.createStatement();
                    String load = "Select * from Store_info_table where PART_NUMBER = '" + field.getText() + "'";
                    ResultSet rs = st.executeQuery(load);
                    while(rs.next()){
                       txtName.setText(rs.getString("SPARE_DESC"));
                    }
                }catch(Exception ae){
    
                }*/
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys have a div that is outside of a table and I want
Hey guys, I have a regular expression that is pretty long, and is hard
Guys, I have been surfing thru the web to find a way that I
Our infrastructure guys have told me that it's not possible to assign SSL Cert.
I have a list of pages that I want to list in the sidebar
I have recently found out that anything Swing(NetBeans, IDEA) is excruciatingly slow to paint
Since you guys have been very helpful in my early steps into the Play
You guys have helped me on number of occasions and I need you once
I want to begin with Thank you, you guys have been good to me.
Do you guys have any idea on doing a winform that will detect the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.