airrazor
10-08-2005, 01:21 AM
Hi everyone.
I finally have a connection with Mysql and a simple java program. I can select and display everything in the database in the command line console. I can change values in the database if I hard wire them into the code everytime. But I have a GUI interface that I want to be able to type in some text and then press a button and the database value is changed to what I wrote in the text box.
I have a JTextbox, where I want to get my text from and I have a JButton to press to execute the change. Am I doing it right so far?? I would like to take what ever is in the textbox and insert it into the databse. How can I acheive this? I tried to use a String variable in the java code and insert it into the query statment but that just gives me an error message when I hit the button to insert it into the database.
This is a snippet of code:
String v="12";
st.executeUpdate("UPDATE male " +
"SET age= v"+
"WHERE fname='richard'"
);
I can understand that the statement sends a string to MySql and I want to insert a variable so it wouldn't work. How would you then make this work??
airrazor
I finally have a connection with Mysql and a simple java program. I can select and display everything in the database in the command line console. I can change values in the database if I hard wire them into the code everytime. But I have a GUI interface that I want to be able to type in some text and then press a button and the database value is changed to what I wrote in the text box.
I have a JTextbox, where I want to get my text from and I have a JButton to press to execute the change. Am I doing it right so far?? I would like to take what ever is in the textbox and insert it into the databse. How can I acheive this? I tried to use a String variable in the java code and insert it into the query statment but that just gives me an error message when I hit the button to insert it into the database.
This is a snippet of code:
String v="12";
st.executeUpdate("UPDATE male " +
"SET age= v"+
"WHERE fname='richard'"
);
I can understand that the statement sends a string to MySql and I want to insert a variable so it wouldn't work. How would you then make this work??
airrazor