Save a textfield data/values into mysql database.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wheninrome
    New Member
    • Sep 2014
    • 1

    Save a textfield data/values into mysql database.

    Good day everyone, I'm trying to save an inputted data using JTextfield in JAVA GUI into MySQL database.
    But when i pressed the save button nothing happens. I want to show you all my work right now.
    Please try to help me, Thank you in advance!

    Code:
    	if(e.getSource().equals(save))	{
    	
    	String ID=custid.getText();
    	int custid=Integer.parseInt(ID);
    	
    	String fname=CustFName.getText();
    	String lname=CustLName.getText();
    	String tel=CustTelNum.getText();
    	String city=CustCity.getText();
    	String zcode=CustZCode.getText();
    	String status=CustStat.getText();
    	String creditcard=CreditCNum.getText();
    	String order=CustOrDt.getText();
    	String dfee=CustDFee.getText();
    	String inumber=MnuINum.getText();
    	String icost=MnuCost.getText();
    	String tcost=TotalCost.getText();
    	
    	try	{
    	rs.moveToInsertRow();
    	
    	rs.updateInt(ID, custid);
    	rs.updateString("First_Name", fname);
    	rs.updateString("Last_Name", lname);
    	rs.updateString("Tel_Num", tel);
    	rs.updateString("City", city);
    	rs.updateString("Zip_Code", zcode);
    	rs.updateString("Status", status);
    	rs.updateString("Credit_Card", creditcard);
    	rs.updateString("Order_Date", order);
    	rs.updateString("Delivery", dfee);
    	rs.updateString("Quantity", inumber);
    	rs.updateString("Item_Cost", icost);
    	rs.updateString("Total_Cost", tcost);
    	
    	rs.insertRow();
    	st.executeQuery("INSERT INTO thepizzadb.orderstable VALUES (ID,'fname','lname','tel'","'city','zcode','status','creditcard','order','dfee','inumber','icost','tcost')");
    
    	st.close();
    	rs.close();
    	
    	
    	}catch(SQLException err){
    		JOptionPane.showMessageDialog(null, err.getMessage());
    	}
    }
    Last edited by Rabbit; Sep 27 '14, 05:43 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Try to put the SQL-statement, that you are sending to the MySQL database at line #7 on a MySQL-prompt, and see if it returns any errors, and if you get the correct values in the database.

    I'm not an expert in JAVA, but this SQL seems not correct for what you want to achieve:
    Code:
    INSERT INTO thepizzadb.orderstable VALUES (ID,'fname','lname','tel'","'city','zcode','status','creditcard','order','dfee','inumber','icost','tcost')"

    Comment

    Working...