Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Java 2 - Assignment

Java 2 - Assignment

Ratings: (0)|Views: 27 |Likes:

More info:

Published by: Muhammad Rana Farhan on Feb 11, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/13/2011

pdf

text

original

 
 Assignment 
============================================import java.util.Scanner;import java.sql.*;class MyDb{Scanner sc=new Scanner(System.in);MyDb(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:MyDSN");st=con.createStatement();System.out.println("Sucessfully Connected");}catch(Exception e){e.printStackTrace();}}public void searchPerson(){String s;System.out.println("Enter Name: ");s=sc.next();try{String qry="select * from person wherename='"+s+"'";rs=st.executeQuery(qry);while(rs.next()){System.out.println(rs.getString(1)+ " "+ " " +rs.getString(2)+ " " + rs.getString(3) );}}catch(Exception e){e.printStackTrace();}}public void addPerson(){String s1,s2,s3;System.out.println("Enter Name: ");s1=sc.next();System.out.println("Enter Address: ");s2=sc.next();System.out.println("Enter Phone#: ");s3=sc.next();try{
 
con.setAutoCommit(false);String qry="INSERT INTO Personvalues('"+s1+"','"+s2+"','"+s3+"')";st.executeUpdate(qry);con.commit();}catch(Exception e){e.printStackTrace();}}public void deletePerson(){String s;System.out.println("Enter Name: ");s=sc.next();try{con.setAutoCommit(false);String qry="delete from person wherename='"+s+"'";st.executeUpdate(qry);con.commit();}catch(Exception e){e.printStackTrace();}}public void updatePerson(){String s,s1,s2,s3;System.out.println("Enter Name to update: ");s=sc.next();System.out.println("Enter Name: ");s1=sc.next();System.out.println("Enter Address: ");s2=sc.next();System.out.println("Enter Phone#: ");s3=sc.next();String qry="update person setname='"+s1+"',address='"+s2+"',phone='"+s3+"' wherename='"+s+"'";try{con.setAutoCommit(false);st.executeUpdate(qry);con.commit();}catch(Exception e){e.printStackTrace();}}public void menu(){System.out.println("1-Search a Person");

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->