Graded Lab 3
Graded Lab 3
Instructions:
Problems:
Note:
1. Paste the outputs of each step you perform.
2. Below given are the questions.
3. The LAST DIGIT of Student Sap Id is given with corresponding database
table details.
1. Sap id ending with digit 0,5 will create the table of employee with columns.
Enter up to 5 employee details only.
2. Sap id ending with digit 1,2,8,9 will create the table of medicines with
columns. Enter up to 5 medicines details.
3. Sap id ending with digit 3,4,6,7 will create the table of students with
columns. Enter up to 5 students details.
Source Code:
import java.sql.*;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/mydatabase",
"username", "password");
stmt = conn.createStatement();
stmt.executeUpdate("CREATE TABLE students (student_name VARCHAR(50),
roll_number INT, Sap_Id INT, favourite_subject VARCHAR(50))");
while (rs.next()) {
System.out.println(rs.getString("student_name") + "\t" +
rs.getInt("roll_number") + "\t" + rs.getInt("Sap_Id") + "\t" +
rs.getString("favourite_subject"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
finally {
try {
if (rs != null)
{
rs.close();
}
if (stmt != null)
{
stmt.close();
}
if (conn != null)
{
conn.close();
}
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Output :