Skip to main content

Posts

Showing posts with the label Java PreparedStatement

Write a Java program to accept the details of Teacher(tno, name, salary) from the user and store into the database table and update the salary of techer yo entered salary amount and tno.

Write a Java program to accept the details of Teacher(tno, name, salary) from the user and store into the database table and update the salary of techer yo entered salary amount and tno. Program: import java.io.*; import java.sql.*; class Teacher { public static void main(String args[]) throws SQLException, ClassNotFoundException, IOException { int tno, salary, choice, r; String name; Statement s; ResultSet rs; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:teacherDSN"); do { System.out.println("Menu"); System.out.println("\n 1. Add Teacher \n 2. Update Teacher Salary"); switch(choice) { case 1: PreparedStatement ps = con.prepareStatement("insert into Teacher values(...

Write a Java program to accept details of Doctor(dno, dname, salary) from the user and insert it into the database(Use PreparedStatement class and AWT).

Write a Java program to accept details of Doctor(dno, dname, salary) from the user and insert it into the database(Use PreparedStatement class and AWT). Program: import java.io.*; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; public class Doctor extends Frame implements ActionListener { Label labelDNo, labelDName, labelSalary; TextField textDNo, textDName, textSalary; Button btnAdd; btnExit; public Doctor() { labelDNo = new Label("Doctor No:"); labelDName = new Label("Doctor Name:"); labelSalary = new Label("Doctor Salary:"); textDNo = new TextField(20); textDName = new TextField(20); textSalary = new TextField(20); btnAdd = new Button("Add"); btnExit = new Button("Exit"); setLayout(new GridLayout(4,2)); add(labelDNo); add(textDNo); add(labelDName); add(textDN...

Write a Java program to accept the details of student (rollNo, name, percentage) from the user and insert it into the table (Use PreparedStatement class)

Write a Java program to accept the details of student (rollNo, name, percentage) from the user and insert it into the table (Use PreparedStatement class) Program: import java.sql.*; import java.io.*; class Student { public static void main(String args[]) throws SQLException, ClassNotFoundException, IOException { String name; int rollNo; float percentage; char ch; BufferedReader br; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); COnnection con = DriverManager.getConnection("jdbc:odbc:studentDSN"); do { PreparedStatement stmt = con.prepareStatement("insert into student values(?,?,?)"); br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Roll No:"); rollNo = Integer.parseInt(br.readLine()); System.out.println("Enter Name:"); name = br.readLine(); ...