import java.io.*;
import java.sql.*;
public class DTest2
{
static BufferedReader br;
static Connection con;
static Statement st;
public static void main(String[] arg)throws IOException,SQLException,ClassNotFoundException
{
br=new BufferedReader(new InputStreamReader(System.in));
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc

dbc:TestDB";
Class.forName(driver);
con=DriverManager.getConnection(url);
//String q="CREATE TABLE info(Name char(10),Email char(30))";
//st=con.createStatement();
//st.execute(q);
System.out.print("Enter\n1.Insert\n2.View\n3.Exit ");
int i=Integer.parseInt(br.readLine());
while(i!=3)
{
if(i==1)
{
insert();
}
else if(i==2)
{
view();
}
System.out.print("Enter\n1.Insert\n2.View\n3.Exit ");
i=Integer.parseInt(br.readLine());
}
}
static void insert()throws IOException,SQLException,ClassNotFoundException
{
System.out.print("\nEnter Name: ");
String name=br.readLine();
System.out.print("\nEnter Email: ");
String mail=br.readLine();
String q1="INSERT INTO info VALUES(?,?)";
PreparedStatement ps=con.prepareStatement(q1);
ps.setString(1,name);
ps.setString(2,mail);
ps.execute();
System.out.println("Record Inserted");
}
static void view()throws SQLException,IOException,ClassNotFoundException
{
String q2="SELECT * FROM info";
st=con.createStatement();
ResultSet rs=st.executeQuery(q2);
while(rs.next())
{
System.out.print(rs.getString(1)+"\t");
System.out.println(rs.getString(2));
}
}
}