Results 1 to 2 of 2
  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default deleting records in a db

    i am trying to delete all records locally on my db. here is my code:

    Java Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    
    public class DeleteAllDBRecords {
    
    	public static void main(String[] args) {
    		
    		try {
    	
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			String dataSourceName = "first test";
    			String dbUrl = "jdbc:odbc:" + dataSourceName;
    			Connection con = DriverManager.getConnection(dbUrl, "", "");
    			Statement s = con.createStatement();
    
    			s.execute("DELETE * FROM members");
    	
    			s.close();
    			con.close();
    	
    		} catch (Exception e) {
    			System.out.println(e);
    		}
    	}
    }
    I get this error: java.sql.SQLException: [MySQL][ODBC 5.1 Driver][mysqld-5.5.17]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM members' at line 1

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: deleting records in a db

    See the following link for the proper syntax of an SQL delete statement
    SQL DELETE Statement
    Note the lack of a wildcard in the examples

Similar Threads

  1. Throttling records
    By jitman in forum New To Java
    Replies: 0
    Last Post: 03-11-2010, 06:18 PM
  2. Moving records from one Arraylist to another?
    By JavaStudent23 in forum New To Java
    Replies: 4
    Last Post: 02-17-2010, 09:52 PM
  3. insert records
    By rudravaram in forum JDBC
    Replies: 3
    Last Post: 01-03-2010, 05:54 PM
  4. How to delete the records
    By kiran kumar in forum Java Servlet
    Replies: 6
    Last Post: 11-09-2008, 01:16 PM
  5. Replies: 0
    Last Post: 02-09-2008, 08:31 PM

Posting Permissions

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