java program to Insert Data Into MsAccess database////////////First u need to do database setting After Use //////////////////////This Program
import java.sql.*;
public class Exp11
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers are properly loaded");
System.out.println("-------------------------------------");
Connection con= DriverManager.getConnection("jdbc:odbc:D2");
System.out.println("Connection established");
System.out.println("-------------------------------------");
String url= "INSERT into Emp values(01, 'Prashant','Mumbai','Maharastra',100000,777,'MD')";
PreparedStatement stmt = con.prepareStatement(url);
stmt.executeUpdate();
System.out.println("first value is inserted");
System.out.println("-------------------------------------");
String url1="INSERT into Emp values(02, 'Prashanti','Haidrabad','Tamilnadu',10000,775,'AS_MD')";
PreparedStatement stmt1 = con.prepareStatement(url1);
stmt1.executeUpdate();
System.out.println("second value is inserted");
System.out.println("-------------------------------------");
String url2="INSERT into Emp values(03, 'Prashantina','Pune','Maharastra',200000,774,'CEO')";
PreparedStatement stmt2 = con.prepareStatement(url2);
stmt2.executeUpdate();
System.out.println("Third value is inserted");
System.out.println("-------------------------------------");
String url3="INSERT into Emp values(04, 'Pradynesh','Bandup','Maharastra',20000,773,'Manager')";
PreparedStatement stmt3 = con.prepareStatement(url3);
stmt3.executeUpdate();
System.out.println("Forth value is inserted");
System.out.println("-------------------------------------");
String url4="INSERT into Emp values(05, 'Pradynesha','Mulund','Maharastra',25000,772,'AS_Manger')";
PreparedStatement stmt4 = con.prepareStatement(url4);
stmt4.executeUpdate();
System.out.println("Fifth value is inserted");
System.out.println("-------------------------------------");
System.out.println("All Data is succesfully inserted");
System.out.println("-------------------------------------");
System.out.println("Connection closed");
con.close();
}
catch (SQLException e)
{
System.err.println("SQL error has been occure");
}
catch (Exception e)
{
System.err.println("Error connection not established");
}
}
}
OutPut:---------
import java.sql.*;
public class Exp11
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers are properly loaded");
System.out.println("-------------------------------------");
Connection con= DriverManager.getConnection("jdbc:odbc:D2");
System.out.println("Connection established");
System.out.println("-------------------------------------");
String url= "INSERT into Emp values(01, 'Prashant','Mumbai','Maharastra',100000,777,'MD')";
PreparedStatement stmt = con.prepareStatement(url);
stmt.executeUpdate();
System.out.println("first value is inserted");
System.out.println("-------------------------------------");
String url1="INSERT into Emp values(02, 'Prashanti','Haidrabad','Tamilnadu',10000,775,'AS_MD')";
PreparedStatement stmt1 = con.prepareStatement(url1);
stmt1.executeUpdate();
System.out.println("second value is inserted");
System.out.println("-------------------------------------");
String url2="INSERT into Emp values(03, 'Prashantina','Pune','Maharastra',200000,774,'CEO')";
PreparedStatement stmt2 = con.prepareStatement(url2);
stmt2.executeUpdate();
System.out.println("Third value is inserted");
System.out.println("-------------------------------------");
String url3="INSERT into Emp values(04, 'Pradynesh','Bandup','Maharastra',20000,773,'Manager')";
PreparedStatement stmt3 = con.prepareStatement(url3);
stmt3.executeUpdate();
System.out.println("Forth value is inserted");
System.out.println("-------------------------------------");
String url4="INSERT into Emp values(05, 'Pradynesha','Mulund','Maharastra',25000,772,'AS_Manger')";
PreparedStatement stmt4 = con.prepareStatement(url4);
stmt4.executeUpdate();
System.out.println("Fifth value is inserted");
System.out.println("-------------------------------------");
System.out.println("All Data is succesfully inserted");
System.out.println("-------------------------------------");
System.out.println("Connection closed");
con.close();
}
catch (SQLException e)
{
System.err.println("SQL error has been occure");
}
catch (Exception e)
{
System.err.println("Error connection not established");
}
}
}
OutPut:---------
No comments:
Post a Comment