Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***SQL** Create your own short and simple JDBC Java code example that creates a

ID: 670486 • Letter: #

Question

***SQL**

Create your own short and simple JDBC Java code example that creates a table with 4 columns in it and then inserts 2 records into that table. The tablename and columns are to be selected by the student.

From a design perspective, the Java functionality should be separated into methods and use prepared Statements for your SQL statements.

Post your fully functional code along with screen shots demonstrating the successful running of it.

Note this code should compile and run from the command prompt.

Explanation / Answer

preparedStatement = conn.prepareStatement(sql1);

preparedStatement.executeUpdate();

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  

String sql2="Insert into REGISTRATION values(?,?,?,?)"; // For insert record

preparedStatement = conn.prepareStatement(sql2);

while(count>0) { // this loop will execute 2 times because you are asked for 2 records only

System.out.println("enter id:");  

int id=Integer.parseInt(br.readLine());  

System.out.println("enter First name:");

String Fname=br.readLine();

System.out.println("enter Last name:");  

String Lname=br.readLine();

System.out.println("enter age");  

int age=Integer.parseInt(br.readLine());  

preparedStatement .setInt(1,id);

preparedStatement.setInt(4,age);

   ps.executeUpdate();

  System.out.println(i+" records affected");

count-- ;

}

}catch(SQLException se){