Skip to main content
added 1 character in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

inside of a method Connectiondb where I give the SQL String (without then rewrite this code every time in each GUI)? I created the method Connectiondb.loadDriver_doConnection_backConn()Connectiondb.loadDriver_doConnection_backConn() because I always treat the data in the buttons GUI and not in the Connectiondb class. This is also the same for the insert and update, but now I can't find a right way.

For the "preparedStatement method" i'mpreparedStatement method I'm writing this code:

There is a better way to do this? (In this way iI have to write other 4 methods for the JFormattedTextFieldJFormattedTextField)

inside of a method Connectiondb where I give the SQL String (without then rewrite this code every time in each GUI)? I created the method Connectiondb.loadDriver_doConnection_backConn() because I always treat the data in the buttons GUI and not in the Connectiondb class. This is also the same for the insert and update, but now I can't find a right way.

For the "preparedStatement method" i'm writing this code:

There is a better way to do this? (In this way i have to write other 4 methods for the JFormattedTextField)

inside of a method Connectiondb where I give the SQL String (without then rewrite this code every time in each GUI)? I created the method Connectiondb.loadDriver_doConnection_backConn() because I always treat the data in the buttons GUI and not in the Connectiondb class. This is also the same for the insert and update, but now I can't find a right way.

For the preparedStatement method I'm writing this code:

There is a better way to do this? (In this way I have to write other 4 methods for the JFormattedTextField)

added 948 characters in body
Source Link

For the "preparedStatement method" i'm writing this code:

static void SetString(PreparedStatement ps, Integer[] indexstring, JTextField[] textstring){
    for (int i=0;i<indexstring.length;i++)
        try {
            ps.setString(indexstring[i], textstring[i].getText().trim());
        } catch (SQLException e) {
            //msg with error
        }
}

static void SetInt(PreparedStatement ps, Integer[] indexint, JTextField[] textint){
    for (int i=0;i<indexint.length;i++)
        try {
            ps.setInt(indexint[i], Integer.parseInt(textint[i].getText().trim()));
        } catch (SQLException e) {
            //msg with error
        }
}

static void SetDouble(PreparedStatement ps, Integer[] indexdouble, JTextField[] textdouble){
    //etc
}

 static void SetDate(PreparedStatement ps, Integer[] indexdate, JTextField[] textdate){
     //etc
 }

There is a better way to do this? (In this way i have to write other 4 methods for the JFormattedTextField)

For the "preparedStatement method" i'm writing this code:

static void SetString(PreparedStatement ps, Integer[] indexstring, JTextField[] textstring){
    for (int i=0;i<indexstring.length;i++)
        try {
            ps.setString(indexstring[i], textstring[i].getText().trim());
        } catch (SQLException e) {
            //msg with error
        }
}

static void SetInt(PreparedStatement ps, Integer[] indexint, JTextField[] textint){
    for (int i=0;i<indexint.length;i++)
        try {
            ps.setInt(indexint[i], Integer.parseInt(textint[i].getText().trim()));
        } catch (SQLException e) {
            //msg with error
        }
}

static void SetDouble(PreparedStatement ps, Integer[] indexdouble, JTextField[] textdouble){
    //etc
}

 static void SetDate(PreparedStatement ps, Integer[] indexdate, JTextField[] textdate){
     //etc
 }

There is a better way to do this? (In this way i have to write other 4 methods for the JFormattedTextField)

deleted 45 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

java code using Using database connection and GUI

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.

java code using database connection and GUI

i'm writing a project with Java. In my project there are a lot of GUI so i have a class for each gui. I created a class to connect to my db (mysql). Remember, i don't have problems with code not working. The code (important to this question) in the connectiondb class is:

And now i'm showing you an example (with no try-catch to control input) of my code on a GUI where i do an insert/delete:

The update is similar. So, in this way, i use the doQuery2 method of Connectiondb.class only for the try-catch control of input, for example:

I use the second parameter when i have to put the data in jtable etc. but it's not important here. So my question is: There is a better way to manage all of this? For example adding other methods in Connectiondb? I use these insert/delete..in the GUIs many times and I think management is not efficient, maybe because i didn't create the classes for the date. For example: a class to take the informations of a person (with get, set), of a company or what i need. I didn't do that because I treat the data directly to the database, i'm wrong? For example there is a way to do this code

inside of a method Connectiondb where i give the sql String? (without then rewrite this code every time in each gui) I created the method Connectiondb.loadDriver_doConnection_backConn() because i treat the data always in the bottons GUI and not in Connectiondb class. This is Also the same for the insert and update but now i don't found a right way.

Using database connection and GUI

In my project there are a lot of GUI so I have a class for each GUI. I created a class to connect to my db (MySQL). Remember, I don't have problems with code not working. The code (important to this question) in the connectiondb class is:

And now I'm showing you an example (with no try-catch to control input) of my code on a GUI where I do an insert/delete:

The update is similar. So, in this way, I use the doQuery2 method of Connectiondb.class only for the try-catch control of input, for example:

I use the second parameter when I have to put the data in jtable etc., but it's not important here.

Is there a better way to manage all of this, such as adding other methods in Connectiondb? I use these insert/delete in the GUIs many times and I think management is not efficient, maybe because I didn't create the classes for the date. For example, a class to take the information of a person (with get, set) of a company or what I need. I didn't do that because I treat the data directly to the database.

For example, is there a way to do this code

inside of a method Connectiondb where I give the SQL String (without then rewrite this code every time in each GUI)? I created the method Connectiondb.loadDriver_doConnection_backConn() because I always treat the data in the buttons GUI and not in the Connectiondb class. This is also the same for the insert and update, but now I can't find a right way.

Source Link
Loading