Win a copy of liveProject: Build an ML Recommender System this week in the Artificial Intelligence and Machine Learning forum!

mitchell bat

Ranch Hand
+ Follow
since Mar 17, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by mitchell bat

Hey guys, up until now I've been writing programs with only 1 or 2 frames tops but now I think i'm ready to move on to slightly more complex things but whilst thinking about the best way to maintain and manage the code I've come across one thing that sticks in my head. What happens to a program that needs to handle multiple frames in a swing program? Do you create one class to manage all of the interfaces or do you create a new class every time you need to use a new frame/layout? Also, is it good practice to dispose of jframes and then create a new one?
4 years ago
Reading that just blew my mind. I'll check it out, try it out and hopefully come back with questions
4 years ago


You shou‍ld not use two frames. You should make dialogue windows visible if you need something to appear and disappear. As an alternative, you can use card layout to make the components you want visible come to the front, and later go to the back and disappear from view. Multiple frames sounds like a bad idea.



Why is having 2 or more frames a bad idea?

Also, when it comes to storing the data in the database is the best way to do it by having the code in the action listener or is there a better way?


You shou‍ld never assume anything in programming. You shou‍ld ask somebody who knows the answer or look in the API documentation (or both). The setString method adds a String to the database update; if, later, the update is successfully executed, the String is added to the database. In that case, if issueDBField is a String, it is badly named. The name of a variable shou‍ld make it obvious what it means; that name obscures its meaning and confused me into thinking it was a field of some sort. Remember that Swing has about three classes called JSomethingField.



If you look at this code here



You can see that i've stored the input taken from the issueArea which is JTextArea as the String issueDBField.

What I don't understand is why it's not storing in the database. That's all I want it to do.
4 years ago


Don't know, but it looks wrong to dispose the frame when you have not finished with it. It also looks wrong to create a new instance at the end of the method.



Because i'm still very new to programming that's how I have created my buttons when I need to go from one frame to another


Can you access the database without the GUI?



Yeah I can, I validated it


I presume also that you have a (public?) interface to your business logic which can be used by the GUI.



Your assumption is correct


What are you going to do if you open a branch at Adelaide?



For now this is just a muck around project to learn programming, when i'm done with this I plan on using the MVC approach which will allow allow for different things such as scalability just like how you mentioned about opening a branch in Adelaide.


Why are you calling setString(1, issueDBField)? Is that field suitable for use as a String to supply to a database update?



I think that the setString method taking the issueDBField string and storing it inside the database. Is that the wrong assumption?

4 years ago
Could the



code have something to do with it?
4 years ago
Hey guys, i've got a question. I've created a form in java which tries to take the inputted information and then stores it in a MySQL database. At the moment what i've got is a login page that goes into the form page and when the submit button is selected the captured information gets sent to the database. I've got 2 main issues/questions, firstly i've got the button (action listener) handling the input to the database, is that the right thing to do? And secondly, when I log in the program skips the form page and goes to the frame after the form page. Could this have anything to do with the code inside my action listener or my JDBC connection class?

My connection class looks like this



and my actionListener in the form page looks like this

4 years ago
So I changed afew things around and the null pointer exception has been sorted, now my only problem is when I run the program and click on the login button it takes me to my secondFrame class for a second and then moves onto the next window. It happened ever since I corrected my previous mistakes. Could it be an issue with the connection that the class is trying to make to the database?

Creating a new Connection should not happen in a static method called main()



I created it that way originally so I could test the connection to make sure that the class connects to the database.

Also I would recommend giving it a proper name, with proper parameters (none in this case)



Giving what a proper name?


Also, throw that SQLException, don't catch and log it.



I've completely butchered everything and i'm so lost. I returned the connection object in the JDBC class and then in the secondframe class I created an instance of the JDBC class and then called the function to get a valid connection object.



and then in the SecondFrame class I did this

What is the difference between ConnectionFactory and my JDBC class?

Do I have to call the object from the JDBC class into the secondframe class?
The connection is null is my JDBC class



but when I run the code it still points me back to this line here

Hey guys, i'm trying to create a prepared statement that updates the database when values are input from a text field and then the submit button is clicked. I'll explain what i've done so far

Take the input from a text field



and then validated the data by using the following



and the part i'm stuck on is the prepared statement to insert the value into the database, this is what I have so far



But firstly I keep getting a null pointer exception on line 130 which is this line



I can't seem to figure it out even though I know that the following things cause a null pointer exception


- Calling the instance method of a null object.
- Accessing or modifying the field of a null object.
- Taking the length of null as if it were an array.
- Accessing or modifying the slots of null as if it were an array.
- Throwing null as if it were a Throwable value.




Cheers guys, this should give me plenty of information to work through!