Search For

Simple OPAC Library Sytem

Flag Hide Line Nos
Flagging a Snippet, takes the snippet to Moderator Attention;


0
Simple OPAC library System Using the Event Driven Programs

In this below Program we have used the Microsoft ODBC:JDBC Drivers
Create a MS ACCESS FILE and Create Table in the name of "stu" in the MS ACCESS FILE.
Example table:"stu"
Must be in the following format
booksnobookidbookname
13corejava
24java2
36j2ee

Note:booksno column must to be assign as Autonumber property

Steps for Creating DataSource for Microsoft Access drivers
1.Go to Control Panel and Select Administrative Tools and then select Data Source ODBC icon.
(or)
1.Go to Run(Press Window+R) and type odbcad32.exe to go Data Source ODBC.
2.Press Add Button.
3.Choose the driver for Microsoft Access.
4.Then,Press Finish Button.
5.Type Data Source Name.
6.Then Press "Select Button" and choose the database file which is created already.
7.Then, Press "OK" Button to complete the process.


//Event driven and the concurrent Program 
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 public class Datas extends JFrame implements ActionListener
 { JTextField id;
JTextField name;
JButton next;
JButton addnew;
JPanel p;
static ResultSet res;
static Connection conn;
static Statement stat; 
public Datas(){
super("Our Application");
Container c = getContentPane();
c.setLayout(new GridLayout(5,1));
id = new JTextField(20);
name = new JTextField(20);
next = new JButton("Next BOOK");
p = new JPanel();
c.add(new JLabel("ISBN",JLabel.CENTER));
c.add(id);
c.add(new JLabel("Book Name",JLabel.CENTER));
c.add(name);
c.add(p);
p.add(next);
next.addActionListener(this);
pack();
setVisible(true);
addWindowListener(new WIN());
 }
 public static void main(String args[]) 
{
Datas d = new Datas();try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 
conn = DriverManager.getConnection("jdbc:odbc:custo");
 // cust is the DSNName
stat = conn.createStatement();
res = stat.executeQuery("Select * from stu");
 // Customers is the table name
res.next();
 }
catch(Exception e) 
{System.out.println("Error" +e);
}
d.showRecord(res);
} 
public void actionPerformed(ActionEvent e)
 {
if(e.getSource() == next) 
{try 
{
res.next();
}catch(Exception ee)
 {
}
showRecord(res);
}
} 
public void showRecord(ResultSet res) 
{
try {
id.setText(res.getString(2));
name.setText(res.getString(3));
System.out.println("Book Id:"+res.getString(2)+"\nBookName:"+res.getString(3));
}catch(Exception e) {}
 }
//end of the main 
//Inner class WIN implemented
class WIN extends WindowAdapter 
{
public void windowClosing(WindowEvent w)
 {JOptionPane jop = new JOptionPane(); 
jop.showMessageDialog(null,"Database","Thanks",JOptionPane.QUESTION_MESSAGE);
}
 }
 } 




OPAC Library System using concurrent programming

In this program we used the same table as already created in the name of "stu"


import java.sql.*;
import java.sql.DriverManager.*;
class Ja{
String bookid,bookname;int booksno;
Connection con;Statement stmt;
ResultSet rs;Ja(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:custo");
}catch(Exception e){
System.out.println("connection error");
}
}
void myput()
{

try{
stmt=con.createStatement();
rs=stmt.executeQuery("SELECT * FROM stu");
System.out.println("\nbooksno\tbookid\tbookname");
while(rs.next())
{booksno=rs.getInt(1);
bookid=rs.getString(2);
bookname=rs.getString(3);
System.out.println("\n"+booksno+"\t"+bookid+"\t"+bookname);
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException e)
{System.out.println("sql error");
}}}
class prog1{
 
public static void main(String arg[])
{Ja j=new Ja(); 
j.myput();
}
}

  


Output for currency programming paradigms
booksnobookidbookname
13corejava
24java2
36j2ee