Results 1 to 5 of 5

Thread: update database

  1. #1
    manuzerwa is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default update database

    On need to delete a row from my database but I fail with these codes, please help

    String query = "DELETE FROM IDENTIFICATION WHERE IDmalade='"+ID.getText()+"'";

    Note: IDmalade is a primary key in my database
    ID is a text field name on my form

    Thanks

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: update database

    What was the error message?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    manuzerwa is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: update database

    There is no error message, but when I click on update button my database is not updated

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: update database

    Quote Originally Posted by manuzerwa View Post
    There is no error message, but when I click on update button my database is not updated
    Is the code in your event handler executed at all?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Join Date
    Apr 2012
    Location
    Long Island, NY
    Posts
    6
    Rep Power
    0

    Default Re: update database

    Here try this, Add the MySQL JDBC library to your project and use this code:

    private static String server_username = "";
    private static String server_password = "";
    private static String url = "jdbc:mysql://host/database";

    Connection conn;
    try {

    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    conn = DriverManager.getConnection(url, server_username, server_password);

    String query = "DELETE FROM IDENTIFICATION WHERE IDmalade = '" + ID.getText() + "'";
    Statement st = (Statement) conn.createStatement();
    st.executeUpdate(query);

    st.close();
    conn.close();
    } catch (Exception e) {
    System.err.println(e);
    }

Similar Threads

  1. Replies: 4
    Last Post: 10-01-2011, 05:13 AM
  2. Update table in database
    By CTheSky in forum JDBC
    Replies: 3
    Last Post: 01-30-2011, 05:18 AM
  3. Update a price in a database
    By sandraW in forum New To Java
    Replies: 14
    Last Post: 08-29-2010, 05:41 AM
  4. How to update database using Spring framework
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 04-01-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •