PROJECT SYNOPSIS FILE ON :----
BHABHA COLLEGE OF ENGINEERING
B MAIL
SIGNATURE OF EXTERNAL EXAMINER:-
SIGNATURE OF INTERNAL EXAMINER:-
DA
TA BASE CONNECTIVITY WITH THE HELP OF JAVA
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
/* database connectivity with MS-Access is done
by creating
DataSourceName(dsn) in this example*/
/* Steps to use this example:
* go to ms-access and make a table called
"student_base" and give it a
file name student_base.mdb
* 1. Go to Control Panel
2. Click on Administrative Tools(windows
2000/xp), Click on
ODBC(win98)
3. click on ODBC
4. Then , you will see a ODBC dialog box. Click on
UserDSn
5. Click on Add Button
6. Select Microsoft Access Driver(*.mdb) driver
and click on finish
7. Give a Data Source Name : student_base
8. Then Click on Select
9. Browse on the database name you have
created and click
it:student_base.mdb is a database file where all
data
will be stored
10. Click on OK.
Once the DSN is created, you can do this
example*/
public class AddNewStudent extends JFrame
implements ActionListener {
private JButton btnok,btnexit,btnaddnew;
//buttons
private JTextField tf1,tf2;//textfields
private JLabel lblname,lbladd,lblmsg; //labels
private JPanel p1,p2,p3,psouth; //panels
public AddNewStudent() //constructor
{
//initializing buttons
btnok = new JButton("OK");
[Link](this);
btnexit = new JButton("Exit");
[Link](this);
btnaddnew = new JButton("AddNew");
[Link](this);
//initializing textfields
tf1 = new JTextField(12);
tf2 = new JTextField(12);
//initializing labels
lblname = new JLabel("Name:");
lbladd = new JLabel("Address:");
lblmsg = new JLabel("",[Link]);
//initializing panels
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
psouth = new JPanel();
//adding buttons and label to panel p1
//setting flowlayout
[Link](new FlowLayout());
[Link](btnok);
[Link](btnexit);
[Link](btnaddnew);
//adding lblmsg to panel p3
[Link](lblmsg);
//adding both the panels to new panel,psouth
//settin layout 2:1
[Link](new GridLayout(2,1));
[Link](p3);
[Link](p1);
//adding label and textfields to panel p2
[Link](new GridLayout(3,1));
//setting line and titled border for panel p2
[Link]([Link](Col
[Link]));
[Link]([Link]("
Enter Your
Details"));
[Link](lblname);
[Link](tf1);
[Link](lbladd);
[Link](tf2);
//adding panel to container
[Link]().add(p2,"Center");
[Link]().add(psouth,"South");
[Link](300,300);
[Link](100,200);
[Link]();
}
public static void main(String args[])
{
AddNewStudent ad = new AddNewStudent();
}
//event handling
public void actionPerformed(ActionEvent e)
{
if([Link]()==btnok)
{
PreparedStatement pstm;
ResultSet rs;
String sql;
//if no entries has been made and hit ok
button throw an error
//you can do this step using try clause as well
if(([Link]().equals("")&&([Link]().equals(
""))))
{
[Link]("Enter your details ");
[Link]([Link]);
}
else
{
try
{
//loading the driver
[Link]("[Link]");
//connection object created using
DriverManager class
//student_base is the name of the database
Connection connect =
[Link]("jdbc:odbc:student
_base");
//creating prepared statement object pstm so
that query can be
sent to database
pstm=[Link]("insert into
student_base
values(?,?)");
[Link](1,[Link]());
[Link](2,[Link]());
//execute method to execute the query
[Link]();
[Link]("Details have been added to
database");
//closing the prepared statement and
connection object
[Link]();
[Link]();
}
catch(SQLException sqe)
{
[Link]("SQl error");
}
catch(ClassNotFoundException cnf)
{
[Link]("Class not found error");
}
}
}
//upon clickin button addnew , your textfield
will be empty to
enter
next record
if([Link]()==btnaddnew)
{
[Link]("");
[Link]("");
}
if([Link]()==btnexit)
{
[Link](1);
}
}
}