| Author |
Need advise on live connection with the Database
|
Cyrus Serrano
Ranch Hand
Joined: Sep 29, 2003
Posts: 137
|
|
Hello all, im a newbie on using JDBC, im trying to create a simple java -GUI database program, i would to ask suggestion if im going to keep the connection alive while the program is running to my database, im using JDBC-ODBC bridge. i wish to create a program that has record manipulations such as add,edit,delete,search a record on the the current database. i wish for advice on how the program could be design, especially on manipulating the database and ofcourse the connection. i can use AWT and a bit of swing, but i know AWT is sufficient. Here is my idea of that program first im going to create a main class that extends a Frame Class, there will be buttons incorporated that will serve as the record manipulation commands and i will try to include record navigation(using the result set's next and previous method). Please correct meon these, in manipulating the add,edit,delete - for every button i will make a connection to the database,select the appropriate table, then perform a SQL DDL statement such INSERT,DELETE,UPDATE, then close the connection.. Please guide me on these design. Thank you all... Cyrus
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
|
Your approach is right. When the button is clicked open the connection, perform the apropriate action(INSERT,DELETE etc) and close the connection. Do not keep the connection open.
|
Groovy
|
 |
Sarath Mohan
Ranch Hand
Joined: Mar 17, 2001
Posts: 213
|
|
As a beginner the above design is good. I suggest you should go a little bit forward and use independent classes to handle database operations. One possible solution is as follows. Encapsulate the tables into a class. And create some manager class to manage it. 1. So design a class which creates and returns database connections. 2. Create table encapsuation classes for e.g. Employee.java 3. Create a class which uses Employee.java and database connection class to manage all database manipualations INSERT/DELETE?UPDATE and VIew.. Here we can use Collection class to get a list of records and display on the UI. 4. Use the Manager class in UI to receive User Inputs and respond accrodingly. I hope this is not complicated for you. The advantage is UI is seperated from the business logic. You can concentrate UI and logic seperately.
|
Sarath Mohan
|
 |
 |
|
|
subject: Need advise on live connection with the Database
|
|
|