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 9245065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:10:55+00:00 2026-06-18T09:10:55+00:00

i got this declared in one jframe (Main) Connection con; i want to use

  • 0

i got this declared in one jframe (Main)

 Connection con;

i want to use that same connection in a other jframe(Gegevens)

 try {
        PreparedStatement stat1 = con.prepareStatement("SELECT idrecepten , p.naam , p.achternaam , m.naam , m.fabrikant , m.dosering FROM recepten r JOIN patienten p ON r.patient = p.idpatienten JOIN medicijnen m ON r.medicijn = m.idmedicijnen WHERE r.patient = ? ");
        stat1.setString(1,primarykey[0]);
        ResultSet resultaat = stat1.executeQuery();

        while(resultaat.next())
        {
           gegevens.model2.addElement(resultaat.getString(1)+" "+ resultaat.getString(2) +" "+ resultaat.getString(3)+" "+ resultaat.getString(4) +" "+ resultaat.getString(5) +" " + resultaat.getString(6));
        }

    } catch (SQLException ex) {
        System.out.println(ex);
    } 

as you can see i am filling the model2 from the jframe(Main), but i want to fill the model in the constructor of the OTHER jframe(Gegevens), same result different approach. BUT

i want to use one only database connection so do i or do i not use the same database connect if i do this:

 Main main = new Main();

and then use the connection

 main.con
  • 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-18T09:10:56+00:00Added an answer on June 18, 2026 at 9:10 am

    The best approach is to construct your code so that when the second/other JFrames are instantiated, that you pass the Connection object as a parameter to the constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a class declared like this: class Level { private: std::vector<mapObject::MapObject> features; (...)
I have this code that uses a template parent class A that has one
I've got a javascript include that's declared in the head of the frameset of
I got a bunch of constants that I use for my tests. They look
a bit of a strange one here. I've got a blog that's another 'dip
i create one simple apps.here i want use the one already create apps (name
I've got the following code that does not produce an CA1804 warning (declared variable
Let's say that what I want to do is to validate one million strings,
I'm aware of other posts on this topic but I'm only really one rung
I have created one application in that I need two fragment, So i declared

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.