This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Please help me with organization UI  RSS feed

 
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm newbie programming in java.
I'm doing some forms and in one of them I put some fileds, a button and a JTextArea. The idea is  when I click in button makes a connection to external database and in JTextArea shows me the connection return (if is ok or if is failed and the error).

So I've created a class with the UI and a class (conection name) with the attributes dabase, port, username, password ... that make connection to external database.

I don't know if these organization mode is the best way to make it. I should include class conection in the same class of the UI,? how shoud I pass values of the form to the class conection? by a method?

could you suggest me how to make it? I'm newbie in Java and in OOP

Many thanks and sorry for my English!
 
Saloon Keeper
Posts: 9997
208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You definitely should keep the two separated. The UI should never know anything about the database. Just pass the UI a reference to your database access object, which is responsible for manipulating the database.

You will want to create an instance of DataSource and pass it to the constructor of the class that accesses the database. Store the DataSource in a field which you access when you need to send a query to the database.

Let's say that your application maintains a database for a library. You'd create a database access object for the books, for example. Here's what it could look like:

You'd fire up your application roughly like this:
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!