I will provide you with the MySQL code for creating the student table and make some changes to your Java code to improve it:
sql> CREATE TABLE IF NOT EXISTS student (
s_id INT PRIMARY KEY,
s_nameVARCHAR(255),
s_addressVARCHAR(255)
);
This SQL code creates a table with three columns: s_id for student ID (primary key), s_name for student name, and s_address for student address.
import java.sql.*;
import java.util.Scanner;
public class InsertData {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "");
Statements = con.createStatement()) {
Scanner sc = new Scanner(System.in);
System.out.println("Inserting Data into student table:");
System.out.println("________________________________________");
System.out.print("Enter student id: ");
int sid = sc.nextInt();
System.out.print("Enter student name: ");
String sname = sc.next();
System.out.print("Enter student address: ");
String saddr = sc.next();
String insertQuery = "INSERT INTO student VALUES(" + sid + ",'" + sname + "','" + saddr + "')";
s.executeUpdate(insertQuery);
System.out.println("Data inserted successfully into student table");
} catch (SQLException err) {
System.out.println("ERROR: " + err);
}
}
}
Inserting Data into student table: ________________________________________ Enter student id: 101 Enter student name: John Doe Enter student address: 123 Main Street Data inserted successfully into student table
import java.sql.*;
import java.util.Scanner;
public class UpdateData {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "");
Statements = con.createStatement()) {
Scanner sc = new Scanner(System.in);
System.out.println("Update Data in student table:");
System.out.println("________________________________________");
System.out.print("Enter student id: ");
int sid = sc.nextInt();
System.out.print("Enter student name: ");
String sname = sc.next();
System.out.print("Enter student address: ");
String saddr = sc.next();
String updateQuery = "UPDATE student SET s_name='" + sname + "', s_address='" + saddr + "' WHERE s_id=" + sid;
s.executeUpdate(updateQuery);
System.out.println("Data updated successfully");
} catch (SQLException err) {
System.out.println("ERROR: " + err);
}
}
}
Update Data in student table: ________________________________________ Enter student id: 101 Enter student name: Jane Doe Enter student address: 456 Broad Street Data updated successfully
import java.sql.*;
import java.util.Scanner;
public class DeleteData {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "");
Statements = con.createStatement()) {
Scanner sc = new Scanner(System.in);
System.out.println("Delete Data from student table:");
System.out.println("________________________________________");
System.out.print("Enter student id: ");
int sid = sc.nextInt();
String deleteQuery = "DELETE FROM student WHERE s_id=" + sid;
s.executeUpdate(deleteQuery);
System.out.println("Data deleted successfully");
} catch (SQLException err) {
System.out.println("ERROR: " + err);
}
}
}
Delete Data from student table: ______________________________________ Enter student id: 101 Data deleted successfully
import java.sql.*;
public class DisplayData {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "");
Statement s = con.createStatement()) {
ResultSet rs = s.executeQuery("SELECT * FROM student");
if (rs != null) {
System.out.println("SID \t STU_NAME \t ADDRESS");
System.out.println("________________________________________");
while (rs.next()) {
System.out.println(rs.getString("s_id") + " \t " + rs.getString("s_name") + " \t " + rs.getString("s_address"));
System.out.println("________________________________________");
}
}
} catch (SQLException err) {
System.out.println("ERROR: " + err);
}
}
}
SID STU_NAME ADDRESS ________________________________________ 102 Alice Smith 789 Oak Avenue ________________________________________ 103 Bob Johnson 567 Pine Road ________________________________________
1) Build a responsive web application for shopping cart with registration, login, catalog and cart pages using CSS3 features, flex and grid. View Solution
2) Use JavaScript for doing client – side validation of the pages implemented in the experiment View Solution
3) Explore the features of ES6 like arrow functions, callbacks, promises, async/await. Implement an application for reading the weather information from openweathermap.org and display the information in the form of a graph on the web page. View Solution
4) Develop a java stand alone application that connects with the database (Oracle / mySql) and perform the CRUD operation on the database tables. View Solution
5) Create an xml for the bookstore. Validate the same using both DTD and XSD. View Solution
6) Create a custom server using http module and explore the other modules of Node JS like OS, path, event. View Solution
7) Develop an express web application that can interact with REST API to perform CRUD operations on student data. (Use Postman) View Solution
8) Create a service in react that fetches the weather information from open weathermap.org and the display the current and historical weather information using graphical representation using chart.js View Solution
9) Create a TODO application in react with necessary components and deploy it into github. View Solution