i'm writing a project with Java. In my project there are a lot of GUI so iI have a class for each guiGUI. I created a class to connect to my db (mysqlMySQL). Remember, iI don't have problems with code not working. The code (important to this question) in the connectiondbconnectiondb
class is:
And now i'mI'm showing you an example (with no try-catch to control input) of my code on a GUI where iI do an insert/delete:
The update is similar. So, in this way, iI use the doQuery2doQuery2
method of Connectiondb.classConnectiondb.class
only for the try-catch control of input, for example:
I use the second parameter when iI have to put the data in jtable etc., but it's not important here. So my question is: There is
Is there a better way to manage all of this? For example, such as adding other methods in ConnectiondbConnectiondb
? I use these insert/delete..in in the GUIs many times and I think management is not efficient, maybe because iI didn't create the classes for the date. For example:, a class to take the informationsinformation of a person (with get, set), of a company or what iI need. I didn't do that because I treat the data directly to the database, i'm wrong?.
For example there, is there a way to do this code
inside of a method ConnectiondbConnectiondb
where iI give the sqlSQL String? (without then rewrite this code every time in each guiGUI) I? I created the method Connectiondb.loadDriver_doConnection_backConn() because iI always treat the data always in the bottonsbuttons GUI and not in Connectiondbthe Connectiondb
class. This is Alsoalso the same for the insert and update, but now i don't foundI can't find a right way.