Professional Documents
Culture Documents
New Text Document
New Text Document
New Text Document
Initial preparation for Project, Java Netbean as Front end and MySQL as backend
Down load the driver from the link
-https://dev.mysql.com/downloads/connector/j/5.1.html
Extract the driver zip folder and copy the file �mysql-connector-java-5.1.45-
bin.jar� to the below path:
C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext
Database creation:
Create a database in MySQL command line.
Mysql> create database student;
Mysql> use student
Mysql> create table stu (name varchar(40), rno int NOT NULL , PRIMARY KE(rno) );
Design of Project:
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student","root","rudra123");
//here student is database name, root is username and rudra123 is password
Statement stmt=con.createStatement();
String sql3="delete from stu where rno='"+jTextField2.getText()+"';";
stmt.executeUpdate (sql3);
jTextField1.setText("");
jTextField2.setText("");
JOptionPane.showMessageDialog(null,"Record Deleted....");
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error in connectivity");
JOptionPane.showMessageDialog(null, e); //optional statement to view the error
type
}
Clear All record in a Table:
DefaultTableModel model = (DefaultTableModel)DTable.getModel();
int rows=model.getRowCount();
if(rows>0)
{ for(int i=0;i<rows;i++)
{ model.removeRow(0);
}}}
Show All record in a Table:
//btncls.doClick();
DefaultTableModel model = (DefaultTableModel)DTable.getModel();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student","root","rudra123");
//here student is database name, root is username and rudra123 is password
Statement stmt=con.createStatement();
String query="select * from stu";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
model.addRow(new Object[]{ rs.getString(1),rs.getInt(2)});
} rs.close();
stmt.close();
con.close();
}catch(Exception e) {
JOptionPane.showMessageDialog(null,"Error in connectivity");
JOptionPane.showMessageDialog(null, e);
}}