import java.sql.*;
import java.io.*;
public class Customer
{
public static void main(String arg[])
{
int id,phno;
String nm,add;
try {
DataInputStream din=new DataInputStream(System.in);
System.out.println("Enter information of Customer.");
System.out.println("Enter ID of Customer.");
id=Integer.parseInt(din.readLine());
System.out.println("Enter Name of Customer.");
nm=din.readLine();
System.out.println("Enter Address of Customer.");
add=din.readLine();
System.out.println("Enter Contact_No of Customer.");
phno=Integer.parseInt(din.readLine());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:BCA");
PreparedStatement pst=con.prepareStatement("insert into Customervalues(?,?,?,?)");
pst.setInt(1,id);
pst.setString(2,nm);
pst.setString(3,add);
pst.setInt(4,phno);
int n=pst.executeUpdate();
if(n>0)
{
System.out.println("Record is Inserted...!!!");
}
else {
System.out.println("Error...!!!");
}
pst.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
***OUTPUT***
D:\TY\Adv Java>javac Customer.java
D:\TY\Adv Java>java Customer
Enter information of Customer.
Enter ID of Customer.
1 Enter Name of Customer.
Sachin
Enter Address of Customer.
Loni
Enter Contact_No of Customer.
3 12345 Record is Inserted...!!!
D:\TY\Adv Java\Ass 1>java Customer
Enter information of Customer.
Enter ID of Customer.
2 Enter Name of Customer.
Akshay
Enter Address of Customer.
Malegaon
Enter Contact_No of Customer.
6789 Record is Inserted...!!!
D:\TY\Adv Java\Ass 1>java Customer
Enter information of Customer.
Enter ID of Customer.
3 Enter Name of Customer.
Sanjay
Enter Address of Customer.
Supe
Enter Contact_No of Customer.
78900 Record is Inserted...!!!