Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC Update statement
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


A.K.G.M Dilrukshi
Update statement
2 Answer(s)      3 years and 11 months ago
Posted in : JDBC


I create a access database my program When I click add button bata are adds to the my data base but when i click update button my database is not update I write this program using 3 differfnt notepad pages

MY CarGUI.java

import java.awt.*;

import javax.swing.*; public class CarGUI { public static JButton add,update,del,Clear,sms; public static JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;

public static void main (String args[]) { JFrame f=new JFrame("Car Details"); JPanel p=new JPanel(); p.setLayout(new BorderLayout()); f.add(p); JPanel p2 = new JPanel(); p2.setLayout(new GridLayout(16,2)); p.add(p2); p2.add(new JLabel("Code")); t1=new JTextField(15); p2.add(t1); p2.add(new JLabel("Date")); t2=new JTextField(15); p2.add(t2); p2.add(new JLabel("Title")); t3=new JTextField(15); p2.add(t3); p2.add(new JLabel("Type")); t4=new JTextField(15); p2.add(t4); p2.add(new JLabel("Make")); t5=new JTextField(15); p2.add(t5); p2.add(new JLabel("Model")); t6=new JTextField(15); p2.add(t6); p2.add(new JLabel("Condition")); t7=new JTextField(15); p2.add(t7); p2.add(new JLabel("ECapacity")); t8=new JTextField(15); p2.add(t8); p2.add(new JLabel("Tranmisson")); t9=new JTextField(15); p2.add(t9); p2.add(new JLabel("Melimega")); t10=new JTextField(15); p2.add(t10); p2.add(new JLabel("FuelType")); t11=new JTextField(15); p2.add(t11); p2.add(new JLabel("Year")); t12=new JTextField(15); p2.add(t12); p2.add(new JLabel("Price")); t13=new JTextField(15); p2.add(t13); p2.add(new JLabel("Person")); t14=new JTextField(15); p2.add(t14); p2.add(new JLabel("Contact No")); t15=new JTextField(15); p2.add(t15); p2.add(new JLabel("Mobile No")); t16=new JTextField(16); p2.add(t16);

    JPanel south = new JPanel();
    add = new JButton("Add");

add.addActionListener(new CarHandeler());
    south.add(add);
    update=new JButton("update");
    update.addActionListener(new CarHandeler());
    south.add(update);
    del=new JButton("Delete");
    del.addActionListener(new CarHandeler());
    south.add(del);
    Clear=new JButton("Clear");
    Clear.addActionListener(new CarHandeler());
    south.add(Clear);
    sms=new JButton("Sendsms");
    sms.addActionListener(new CarHandeler());
    south.add(sms);
    p.add(south,BorderLayout.SOUTH);
    f.pack();
    f.setVisible(true);

} }

this is my update query inside CarConnector.java public void update(int code, String dat, String title, String type, String make, String model, String conn,String cap,String tran,String meli,String ftype,String year,String price,String per,String conta,String mobr ) { String query = "UPDATE cars SET Date='" + dat+ "'," + "Title='" +title + "'," + "Type='" +type+ "'," + "Make='" +make+ "'," + "Condition='" +conn+ "'," + "ECapacity='" +cap+ "',"+ "Tranmisson='" +tran+ "',"+"Melimega='"+meli+"',"+"FuelType='"+ftype+"',"+"Year='"+year+"',"+"Price='"+price+"',"+"Person='"+per+"',"+"ContactNo='"+conta+"',"+"MobileNo='"+mobr+"'WHERE Code=" + code + ""; }

MY CarHandelar.java public class CarHandeler extends CarGUI implements ActionListener { CarConnector c=new CarConnector(); public void actionPerformed(ActionEvent e) { String code=t1.getText(); String dat=t2.getText(); String title=t3.getText(); String type=t4.getText(); String make=t5.getText(); String model=t6.getText(); String conn=t7.getText(); String cap=t8.getText(); String tran=t9.getText(); String meli=t10.getText(); String ftype=t11.getText(); String year=t12.getText(); String price=t13.getText(); String per=t14.getText(); String conta=t15.getText(); String mobr=t16.getText(); if(e.getSource()==add) { c.add(Integer.parseInt(code),dat,title,type,make,model,conn,cap,tran,meli,ftype,year,price,per,conta,mobr);

  }
else if(e.getSource()==update)
  {
     c.update(Integer.parseInt(code),dat,title,type,make,model,conn,cap,tran,meli,ftype,year,price,per,conta,mobr);
   }
 else if(e.getSource()==del)
   { 
     c.delete(Integer.parseInt(code));
   }
  else if(e.getSource()==Clear)
 {
   t1.setText("");
   t2.setText("");
   t3.setText("");
   t4.setText("");
   t5.setText("");
   t6.setText("");
   t7.setText("");
   t8.setText("");
   t9.setText("");
   t10.setText("");
   t11.setText("");
   t12.setText("");
   t13.setText("");
   t14.setText("");
   t15.setText("");
   t16.setText("");

 }

else if(e.getSource()==sms) { c.Sendsms(Integer.parseInt(code)); } } } T public void update(int code, String dat, String title, String type, String make, String model, String conn,String cap,String tran,String meli,String ftype,String year,String price,String per,String conta,String mobr ) { String query = "UPDATE cars SET Date='" + dat+ "'," + "Title='" +title + "'," + "Type='" +type+ "'," + "Make='" +make+ "'," + "Condition='" +conn+ "'," + "ECapacity='" +cap+ "',"+ "Tranmisson='" +tran+ "',"+"Melimega='"+meli+"',"+"FuelType='"+ftype+"',"+"Year='"+year+"',"+"Price='"+price+"',"+"Person='"+per+"',"+"ContactNo='"+conta+"',"+"MobileNo='"+mobr+"'WHERE Code=" + code + ""; } PLEASE HELP ME TO SLOVE THIS


Advertisement
View Answers

November 27, 2010 at 5:03 PM


Hi Friend,

The fields Date and Transmission in the database table contradicts. So replace the fields by DD and Trans respectively.

Here is your code:

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class CarGUI implements ActionListener{
public static JButton add,update,del,Clear,sms;
public static JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
    CarGUI(){
    JFrame f=new JFrame("Car Details");
    JPanel p=new JPanel();
    p.setLayout(new BorderLayout());
    f.add(p);
    JPanel p2 = new JPanel();
    p2.setLayout(new GridLayout(16,2));
    p.add(p2); 
    p2.add(new JLabel("Code"));
    t1=new JTextField(15);
    p2.add(t1);
    p2.add(new JLabel("Date"));
    t2=new JTextField(15);
    p2.add(t2);
    p2.add(new JLabel("Title"));
    t3=new JTextField(15);
    p2.add(t3);
    p2.add(new JLabel("Type"));
    t4=new JTextField(15); 
    p2.add(t4);
    p2.add(new JLabel("Make"));
    t5=new JTextField(15);
    p2.add(t5);
    p2.add(new JLabel("Model"));
    t6=new JTextField(15);
    p2.add(t6);
    p2.add(new JLabel("Condition"));
    t7=new JTextField(15);
    p2.add(t7); 
    p2.add(new JLabel("ECapacity"));
    t8=new JTextField(15); p2.add(t8);
    p2.add(new JLabel("Tranmisson"));
    t9=new JTextField(15);
    p2.add(t9);
    p2.add(new JLabel("Melimega"));
    t10=new JTextField(15);
    p2.add(t10);
    p2.add(new JLabel("FuelType"));
    t11=new JTextField(15);
    p2.add(t11);
    p2.add(new JLabel("Year"));
    t12=new JTextField(15);
    p2.add(t12);
    p2.add(new JLabel("Price"));
    t13=new JTextField(15);
    p2.add(t13);
    p2.add(new JLabel("Person"));
    t14=new JTextField(15);
    p2.add(t14);
    p2.add(new JLabel("Contact No"));
    t15=new JTextField(15);
    p2.add(t15);
    p2.add(new JLabel("Mobile No")); 
    t16=new JTextField(16); 
    p2.add(t16);
    JPanel south = new JPanel();
    add = new JButton("Add");
    add.addActionListener(this);
    south.add(add);
    update=new JButton("update");
    update.addActionListener(this);
    south.add(update);
    del=new JButton("Delete");
    del.addActionListener(this);
    south.add(del);
    Clear=new JButton("Clear");
    Clear.addActionListener(this);
    south.add(Clear);
    sms=new JButton("Sendsms");
    sms.addActionListener(this);
    south.add(sms);
    p.add(south,BorderLayout.SOUTH);
    f.pack();
    f.setVisible(true);
}


November 27, 2010 at 5:04 PM


continue....

public void actionPerformed(ActionEvent e) { 
           try{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:student");
         Statement st=con.createStatement();
                    String code=t1.getText();
                    String dat=t2.getText();
                    String title=t3.getText();
                    String type=t4.getText();
                    String make=t5.getText();
                    String model=t6.getText();
                    String conn=t7.getText(); 
                    String cap=t8.getText();
                    String tran=t9.getText();
                    String meli=t10.getText();
                    String ftype=t11.getText();
                    String year=t12.getText();
                    String price=t13.getText();
                    String per=t14.getText();
                    String conta=t15.getText();
                    String mobr=t16.getText();
                    if(e.getSource()==add) {
                        st.executeUpdate("insert into car values('"+Integer.parseInt(code)+"','"+dat+"','"+title+"','"+type+"','"+make+"','"+model+"','"+conn+"','"+cap+"','"+tran+"','"+meli+"','"+ftype+"','"+year+"','"+price+"','"+per+"','"+conta+"','"+mobr+"')");
      }
      else if(e.getSource()==update)  {
    System.out.println(code);
    st.executeUpdate("UPDATE car SET DD='" + dat+ "',Title='" +title + "',Type='" +type+ "',Make='" +make+"',Condition='" +conn+ "',ECapacity='" +cap+ "',Trans='" +tran+ "',Melimega='"+meli+"',FuelType='"+ftype+"',Year='"+year+"',Price='"+price+"',Person='"+per+"',ContactNo='"+conta+"',MobileNo='"+mobr+"' WHERE Code="+Integer.parseInt(code)+"");
      }
    }
         catch(Exception ex){
           System.out.println(ex);
           ex.printStackTrace();
       }
           }
           public static void main (String args[]) { 
    new CarGUI();
           }
       }

Thanks



Related Tutorials/Questions & Answers:
Update statement
Update statement  I create a access database my program When I click add button bata are adds to the my data base but when i click update button my database is not update I write this program using 3 differfnt notepad pages MY
update statement in mysql
update statement in mysql  i am looking for mysql update statement example. Thanks
Advertisements
The Update Statement in SQL.
The Update Statement in SQL.  The Update Statement in SQL.   Hi, here is the answer, The update statement in the sql is written as follows- UPDATE table_name SET column_name = new_value WHERE column_name = some_value
update statement in mysql
update statement in mysql  Update statement to update the existing... and use the update query to update the record. To update record, we write query ?UPDATE student SET fieldName=??? WHERE fieldName=?? . You can SET value
The UPDATE Statement
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through a specified criteria. In the given syntax of update statement the keyword SET
using case in update statement
using case in update statement  i want to use case in update clause... syntax is not working for update stmt.my problem is update emp set case deptno... working but for first condition only update emp set deptno=(case when 10 then 20
The UPDATE Statement, SQL Tutorial
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through a specified criteria. In the given syntax of update statement the keyword SET
HQL Update Statement to update database table
HQL Update Statement to update database table HQL's update query statement is used to update the values of database rows. Though HQL is similar to SQL...()); } } } Output of UPDATE Statement: log4j:WARN No appenders could
JDBC Update Statement Example
.style1 { text-align: center; } JDBC Update Statement Example JDBC update statement is used to update the records of a table using java application program. The Statement object returns an int value that indicates how many
JDBC Prepared Statement Update
JDBC Prepared Statement Update   ... Statement Update is used to update the SQL statement, using where clause... Prepared Statement Update. The code include a class Jdbc Prepared Statement
Statement Batch Update
Statement Batch Update       In this section we are going to learn about the batch update... are added in the Statement object and update the records of database simultaneously
JDBC Batch Example With SQL Update Statement
JDBC Batch Example With SQL Update Statement: In this tutorial, we are discuss about update SQL statement with the jdbc batch. Now we will create a java... of the batch processing with update statement. The code of the BatchUpdate.java
JDBC Batch SQL Update Statement Example With Return Number of Effected Rows
JDBC Batch SQL Update Statement Example With Return Number of Effected Rows: In this example, we are discuss about update statement with return number... represents the update count for the respective update statement. First we
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
how do i update my database with the help of update syntax in html ? How to write 'where' statement in this?  var sqlmek="update into Student_info...'); alert('Press OK to Update your Records Successfully
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.  String sql = "UPDATE emp_details SET empEname = ?, emailId = ?, guid =?, proximityCard =?, managerEmailId = ?, reviewerEmailId
Prepared Statement With Batch Update
Prepared Statement With Batch Update   ... PreparedStatementBatchUpdate Prepared Statement Batch Update Example! Added... with BatchUpdate and we are going to provide an example that performs batch update
Update Record using Prepared Statement
JDBC: Update Record using Prepared Statement In this section, you will learn how to update row using Prepared Statements. Update Record  ... statement. Update record is most important operation of database. You can update one
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data... have one task to do soft parsing tl asked to do callable statement,stored... for update also thank you
PHP MySQL Update
PHP MySQL Update       In SQL, Update is another statement which is used to update any record of a table. This command is useful when we need to update any existing value, which could
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
update
update  Predict and justify the output of the following code snippet written by the developer to update the Status table: String str = "UPDATE m...://localhost:3306/roseindia", "root", "root"); String str = "UPDATE Status SET
for statement
for statement  for(int i=0;i<5;i++); { system.out.println("The value of i is :"+i); } if i end for statement what will be the output   got the answer.. it displays only the last iteration that is "The value of i
how to update
how to update   conditional update
update profile
update profile  coding for update profile
update image
update image  sir, I want to do update image into database
Update - JDBC
in a variable suppose num = 10. Step2: Execute update statement for example reUpdate Emp... is what I used to update normally. It works. Please assist me. Thanks...("jdbc:odbc:Biu"); stat = con.prepareStatement("Update Biu SET itemcode
Statement block
Statement block  What is the purpose of a statement block
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
if statement in php
if statement in php  Correct way of writing if statement in PHP
java if statement
java if statement  If statement in Java
to update the information
to update the information   sir, i am working on library mgt project. front end is core java and backend is ms access.i want to open,update the information through form.please send me code earliar
 

 

 

DMCA.com