DBMS PRG7 LAB
DBMS PRG7 LAB
TOOLS
DATE : (EG., NETBEANS,MySQL)
AIM:
To create a Database Driven applications with Java Netbean with MySQL.
ALGORITHM:
Step-1: Open Mysql and create the DB like as Following
RollNo Integer
Names Varchar(30)
M1 Numberic(5,2)
M2 Numberic(5,2)
M3 Numberic(5,2)
Tot Numberic(5,2)
Ave Numberic(5,2)
Result Varchar(20)
Queries
1. Create database and table like as following
create database studentrecord;
use studentrecord;
2. Insert record into table
create table marklist(RollNo int primary key , Names varchar(30),m1 numeric(5,2)
,m2 numeric(5,2),m3 numeric(5,2),Tot numeric(5,2),ave numeric(5,2),Result varchar(20));
3. View table
Select *from marklist
now form will Appear on the screen ,drag necessary labels and textboxes and buttons
JTextField -1 Rno
JTextField -2 Name
JTextField -3 Sub1
JTextField -4 Sub2
JTextField -5 Sub3
JTextField -6 Total
JTextField -7 Average
JTextField -8 Result1
JButton-1 Result
JButton-2 Insert
JButton-3 Update
JButton-4 Delete
JButton-5 Search
Now form will be like as following
Click ( Test Connection ) …. If you all the above information is true means we go the
message ( i ) – Connection Succeeded..
10. Now we got the link in the services section like as following
11. jdbc:mysql://localhost:3306/peacock?zeroDateTimeBehavior=convertToNull [root on Default
schema]
Step-5:Now Add Jar-file also in our Project
Step-6: Double click on Result Button and type the following codes
private void resultActionPerformed(java.awt.event.ActionEvent evt) {
String s1 = sub1.getText();
String s2 = sub2.getText();
String s3 = sub3.getText();
int n1 = Integer.parseInt(s1);
int n2 = Integer.parseInt(s2);
int n3 = Integer.parseInt(s3);
if(n1>35&&n2>35&&n3>35&&n1<100&&n2<=100&&n3<=100)
{
int t = n1+n2+n3;
float avg = (float)t/3;
total.setText(""+t);
average.setText(""+avg);
result1.setText("PASS");
}
else
{
result1.setText("FAIL/INVALID DATA");
total.setText("");
average.setText("");
}}
To run the Form : Press Shift + F6 ( the form getting result like as following )
Step-6: Insert records in to the Mysql Table
Double click INSERT button and type the following codes
private void insertActionPerformed(java.awt.event.ActionEvent evt) {
try
{
String reg = Rno.getText();
int r=Integer.parseInt(reg);
String name1 = Name.getText();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/studentrecord","root","Krishnan@90") ;
PreparedStatement pst = con.prepareStatement("insert into marklist values (?,?,?,?,?,?,?,?)");
pst.setInt(1, r);
pst.setString(2, name1);
pst.setInt(3,Integer.parseInt(Sub1.getText()));
pst.setInt(4,Integer.parseInt(Sub2.getText()));
pst.setInt(5,Integer.parseInt(Sub3.getText()));
pst.setInt(6, Integer.parseInt(Total.getText()));
pst.setFloat(7, Float.parseFloat(Average.getText()));
pst.setString(8, Result1.getText());
int count = pst.executeUpdate();
System.out.println("Record Inserted");
pst.close();
con.close();
}
catch(SQLException se)
{
System.out.println("Error "+se);
}}
To run the Form : Press Shift + F6 ( the form getting result like as following )
Step-7: Search record from Mysql Table
Double click on Search button