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