Skip to main content

Posts

Showing posts with the label Java database crud

Write a Java Program to insert the details of Actor(ano, name, movie) into database and display result in Uppercase.

Write a Java Program to insert the details of Actor(ano, name, movie) into database and display result in Uppercase. Program: import java.sql.*; import java.io.*; class Actor { public static void main(String args[]) throws SQLException, ClassNotFoundException, IOException { String name, movie; int ano; char ch; BufferedReader br; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); COnnection con = DriverManager.getConnection("jdbc:odbc:actorDSN"); do { PreparedStatement stmt = con.prepareStatement("insert into actor values(?,?,?)"); br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Actor No:"); ano = Integer.parseInt(br.readLine()); System.out.println("Enter Name:"); name = br.readLine(); System.out.println("Enter Movie Name:"); m...

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 display the record of Student(rollNo, name, marks) on the screen by selecting rollno from the choice component.

Write a Java program to display the record of Student(rollNo, name, marks) on the screen by selecting rollno from the choice component. Program: import java.awt.*; import java.awt.event.*; import java.sql.*; import java.io.*; public class Student extends Frame implements ActionListener { Choice rollNo; Connection con; Statement stmt; ResultSet rs; String sql; public Student() throws SQLException, ClassNotFoundException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:patientDSN"); stmt = con.createStatement(); rs.executeQuery("Select * from student"); setSize(300,200); setVisible(true); setLayout(new FlowLayout()); addWindowListener(new WClose()); rollNo.ItemListener(this); while(rs.next()){ rollNo.addItem(String.valueOf(rs.getInt(1))); } add(rollNo); } stmt.close()...

Write a Java program to accept the details of patient(pno, pname) from user and insert it into the database, display it and delete the record of entered pno from the table

Write a Java program to accept the details of patient(pno, pname) from user and insert it into the database, display it and delete the record of entered pno from the table Program: import java.io.*; import java.sql.*; import java.awt.*; import java.awt.event.*; public class Patient extends Frame implements ActionListener { Label labelPNo, labelPName; TextField textPNo, textPName; Button btnAdd, btnDelete; String sql; Statement stmt; Connection con; public Patient() throws SQLException, ClassNotFoundException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:patientDSN"); setLayout(new FlowLayout()); setSize(300,200); labelPNo = new Label("Patient No:"); labelPName = new Label("Patient Name:"); textPNo = new TextField(20); textPName = new TextField(20); btnAdd = new Button("Add"); ...

Write a Java program to accept the empno from user and update the salary of employee and display the updated record on the screen. Employee having fields empno, ename & salary.

Write a Java program to accept the empno from user and update the salary of employee and display the updated record on the screen. Employee having fields empno, ename & salary. Program: import java.sql.*; import java.io.*; class Employee { public static void main(String args[]) { Connection con; Statement stmt; ResultSet rs; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:employeeDSN"); stmt = con.createStatement(); System.out.println("Enter Employee No:"); int empno = Integer.parseInt(br.readLine()); System.out.println("Enter new Salary of Employee:"); int salary = Integer.parseInt(br.readLine()); stmt.executeUpdate("update employee set salary = "+salary+" wh...

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 Menu driven program in java for Insert Record into Table,Update the existing Record and Display all records from the table

Write a Menu driven program in java for the following: 1. Insert Record into Table 2. Update the existing Record 3. Display all records from the table  Program: import java.sql.*; import java.io.*; public class MenuRec { public statuc void main(String args[])throws SQLException, ClassNotFoundException, IOException { int ch,rollNo,marks,k; String name; String sql; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); COnnection con = DriverManager.getConnection("jdbc:odbc:MyDSN"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Statement stmt; do { System.out.println("Menu:"); System.out.println("1. Insert \n 2.Update \n 3.Display:"); System.out.println("Enter Choice:"); ch = Integer.parseInt(br.readLine()); switch(ch) { case 1: stmt = con.cre...

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(); ...

Write a Java program to accept the details of employee(eno, ename, salary) using AWT and insert into database

Write a Java program to accept the details of employee(eno, ename, salary) using AWT and insert into database. Program: import java.awt.*; import java.awt.event.*; import java.io.*; import java.sql.*; public class Employee extends Frame implements ActionListener { Label labelEno, labelEname, labelSalary; TextField textEno, textEname, textSalary; Button btnAdd; String sqlQuery; Statement s; Connection dbConnection; public Employee() throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); dbConnection = DriverManager.getConnection("jdbc.odbc:EmployeeDSN"); setLayout(new FlowLayout()); setSize(300,300); labelEno = new Label("Employee No:"); labelEname = new Label("Employee Name:"); labelSalary = new Label(Employee Salary:); textEno = new TextField(20); textEname = new TextField(20); textSalary = new TextField(20); btnAdd = new Button("Add"); btnAdd.addAction...