Write a java program to insert the details of Actor(Ano,Aname,Movie) into the database and display the result in uppercase on the screen.
import java.sql.*; import java.io.*; import javax.sql.*; class slip15 { public static void main(String args[]) { Connection con; Statement state; ResultSet rs; int ch; boolean flag=true; String decision; int ano; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:my1dsn.dsn"); System.out.println("Statement object created"); do { System.out.println("\n"); System.out.println("Menu:"); System.out.println("1.Insert Record into the table"); System.out.println("2.Display all the records from the table"); System.out.println("3.Exit"); System.out.println("Enter your choice:"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: System.out.println("Enter ActorNo:"); ano=Integer.parseInt(br.readLine()); System.out.println("Enter Actor Name:"); String aname=br.readLine(); System.out.println("Enter Movie:"); String movie=br.readLine(); String sql="Insert into actor values(?,?,?)"; PreparedStatement p=con.prepareStatement(sql); p.setInt(1,ano); p.setString(2,aname); p.setString(3,movie); p.executeUpdate(); System.out.println("Record Added"); break; case 2: state=con.createStatement(); sql="Select * from actor"; rs=state.executeQuery(sql); while(rs.next()) { System.out.println("\n"); System.out.println(rs.getInt("ano")+"\t"+(rs.getString("aname")).toUpperCase()+"\t"+(rs.getString("movie")).toUpperCase()); } break; case 3: System.exit(0); default: System.out.println("Invalid Choice"); break; } } while (ch!=3); } catch(Exception e) { System.out.println(e); } } }
Write a java program to insert the details of Actor(Ano,Aname,Movie) into the database and display the result in uppercase on the screen.
Reviewed by
on
April 27, 2015
Rating: