Thursday, 16 February 2012

How to delete record from Ms Access in Java








rajkumar9795@gmail.com
for delete a record in access follow instruction as mention in file connection blog 

import java.io.*;
import java.sql.*
class filedelete
{
public static void main(String[] args)
{
String dataSourceName = "mdbTEST";
String dbURL = "jdbc:odbc:" + dataSourceName;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "","");                        
String nm;
DataInputStream da=new DataInputStream(System.in);
System.out.print("Enter name ");
nm=da.readLine();
                        Statement s = con.createStatement();
                        s.executeUpdate("delete from user where name='"+nm+"'");
con.close();
System.out.println("Deleted");

}
catch (Exception err)
{
System.out.println( "Error: " + err );
}
}
}