Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC java code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


revenge roshan
java code
0 Answer(s)      3 years and 11 months ago
Posted in : JDBC


import java.io.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.sql.*; import sun.jdbc.odbc.*;

public class menu extends Frame implements WindowListener,ActionListener { MenuBar mb; MenuItem student,rollnowise,namewise,allresult; public static menu m; rollnowise rw; namewise n; student st; int x,y,d;

public menu() { super("menu ARPAN"); addWindowListener(this); x=y=700; d=10; setSize(x,y); setBackground(Color.orange); addMenu(); show(); }

public static void main(String args[]) { m=new menu(); }

void addMenu() { MenuBar mb=new MenuBar(); Menu register=new Menu("REGISTER"); Menu inquery=new Menu("INQUERY"); register.add("STUDENT"); register.add("EXIT"); inquery.add("ROLLNOWISE"); inquery.add("NAMEWISE");

mb.add(register); mb.add(inquery);

setMenuBar(mb);

register.addActionListener(this); inquery.addActionListener(this);

}

public void actionPerformed(ActionEvent ae)

{ String arg=ae.getActionCommand(); if(ae.getSource() instanceof Menu) if(arg.equals("EXIT")) { System.exit(0); } if(ae.getSource() instanceof Menu) if("STUDENT".equals(arg)) { st=new student(); st.show(); } if(ae.getSource() instanceof Menu) if("ROLLNOWISE".equals(arg)) { rw=new rollnowise(); rw.show(); } if(ae.getSource() instanceof Menu) if("NAMEWISE".equals(arg)) { n=new namewise(); n.show(); } }

public void windowClosed(WindowEvent we){} public void windowDeiconified(WindowEvent we){} public void windowIconified(WindowEvent we){} public void windowActivated(WindowEvent we){} public void windowDeactivated(WindowEvent we){} public void windowOpened(WindowEvent we){} public void windowClosing(WindowEvent we) { while(x>0 && y>0) { setSize(x,y); x=x-d; y=y-d; show(); } System.out.println("mail me at arpankumarsingh@yahoo.com"); dispose(); System.exit(0);

} }

//class for name wise report

class namewise extends Frame implements WindowListener,ActionListener { public static namewise nw; Label l1=new Label("NAME",Label.LEFT); Label l2=new Label("ROLLNO",Label.LEFT); Label l3=new Label("COLG",Label.LEFT); Label l4=new Label("SUB1",Label.LEFT); Label l5=new Label("SUB2",Label.LEFT); Label l6=new Label("SUB3",Label.LEFT); Label l7=new Label("SUB4",Label.LEFT); Label l8=new Label("SUB5",Label.LEFT); TextField tf_entername=new TextField(20); Button but_entername =new Button("FIND"); Button ok=new Button("OK"); Graphics g; String sqlstr; Statement st; GridLayout gl=new GridLayout(1,2); GridLayout cl=new GridLayout(1,5);

Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18);

int x,y,d;
Dialog dlg;
Label msg;

public namewise()
{
super("NAMEWISE");
addWindowListener(this);
setLayout(new GridLayout(12,1));
setBackground(Color.orange);
setForeground(Color.black);
addMenu();
x=550;

y=450;
d=100;
setSize(x,y);
show();
}

void addMenu()
{
Panel p4=new Panel();
Label l11=new Label("ENTERNAME");

p4.add(l11);
p4.add(tf_entername);
p4.add(but_entername);
add(p4);

but_entername.addActionListener(this);
ok.addActionListener(this);

//Dialog for confirmation

 dlg=new Dialog(this,"Inventory Management System",false);
 dlg.setLayout(new GridLayout(2,1));
 dlg.setSize(100,100);
 dlg.setLocation(200,100);
 ok.setSize(50,50);
 msg=new Label("NAME NOT FOUND");
 dlg.add(msg);
 dlg.add(ok);

 }

public void actionPerformed(ActionEvent e) { Panel p1=new Panel(); l1.setFont(font18); l2.setFont(font18); p1.setLayout(gl); p1.add(l1); p1.add(l2); g=getGraphics(); g.drawLine(40,0,40,0);

Panel p2=new Panel(); l3.setFont(font18); p2.add(l3); p2.setLayout(gl);

Panel p3=new Panel(); l4.setFont(font18); l5.setFont(font18); l6.setFont(font18); l7.setFont(font18); l8.setFont(font18);

p3.add(l4); p3.add(l5); p3.add(l6); p3.add(l7); p3.add(l8); p3.setLayout(cl);

String arg=e.getActionCommand(); if(e.getSource() instanceof Button) if("FIND".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:stu","",""); sqlstr="select * from stu1 where NAME='"+tf_entername.getText()+"'"; st=con.createStatement(); ResultSet rs; rs= st.executeQuery(sqlstr);

    while(rs.next())
 {
  Panel a1=new Panel();
  l1=new Label("",Label.LEFT);
  l2=new Label("",Label.LEFT);
  l1.setFont(font18);
  l2.setFont(font18);
  a1.setLayout(gl);

  Panel a2=new Panel();
  l3=new Label("",Label.LEFT);
  l3.setFont(font18);
  a2.setLayout(gl);

  Panel a3=new Panel();
  l4=new Label("",Label.LEFT);
  l5=new Label("",Label.LEFT);
  l6=new Label("",Label.LEFT);
  l7=new Label("",Label.LEFT);
  l8=new Label("",Label.LEFT);
  l4.setFont(font18);

   l5.setFont(font18);

   l6.setFont(font18);

   l7.setFont(font18);

   l8.setFont(font18);
   a3.setLayout(cl);

  l1.setText(rs.getString("NAME"));
  l2.setText(""+rs.getInt("ROLLNO"));
  l3.setText(rs.getString("COLG"));
  l4.setText(""+rs.getInt("SUB1"));
  l5.setText(""+rs.getInt("SUB2"));
  l6.setText(""+rs.getInt("SUB3"));
  l7.setText(""+rs.getInt("SUB4"));
  l8.setText(""+rs.getInt("SUB5"));

 a1.add(l1);
 a1.add(l2);

 a2.add(l3);


 a3.add(l4);
 a3.add(l5);
 a3.add(l6);
 a3.add(l7);
 a3.add(l8);

 add(p1);
 add(a1);

 add(p2);
 add(a2);

 add(p3);
 add(a3);
show();
 }

} catch(ClassNotFoundException se) { tf_entername.setText("Error : " + se.toString());

}
catch(SQLException se)
{
  tf_entername.setText("Error : " + se.toString());

}

}

public void windowClosed(WindowEvent we){} public void windowDeiconified(WindowEvent we){} public void windowIconified(WindowEvent we){} public void windowActivated(WindowEvent we){} public void windowDeactivated(WindowEvent we){} public void windowOpened(WindowEvent we){}

public void windowClosing(WindowEvent we) { while(x>0 && y>0) { setSize(x,y); x=x-d; y=y-d; show(); } dispose();

} }

//class for rollnowise report class rollnowise extends Frame implements WindowListener,ActionListener {

public static rollnowise rw; Label l1=new Label("NAME",Label.LEFT); Label l2=new Label("ROLLNO",Label.LEFT); Label l3=new Label("COLG",Label.LEFT); Label l4=new Label("SUB1",Label.LEFT); Label l5=new Label("SUB2",Label.LEFT); Label l6=new Label("SUB3",Label.LEFT); Label l7=new Label("SUB4",Label.LEFT); Label l8=new Label("SUB5",Label.LEFT); TextField tf_entername=new TextField(20); Button but_entername =new Button("FIND"); String sqlstr; Statement st; GridLayout gl=new GridLayout(1,2); GridLayout cl=new GridLayout(1,5);

Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18);

int x,y,d;

public rollnowise() { super("ROLLNOWISE"); addWindowListener(this); setLayout(new GridLayout(12,1)); setBackground(Color.orange); setForeground(Color.black); addMenu(); x=550; y=450; d=100; setSize(x,y); show(); }

void addMenu() { Panel p4=new Panel(); Label l11=new Label("ENTERROLLNO");

p4.add(l11); p4.add(tf_entername); p4.add(but_entername); add(p4);

but_entername.addActionListener(this); }

public void actionPerformed(ActionEvent e) { Panel p1=new Panel(); l1.setFont(font18); l2.setFont(font18); p1.setLayout(gl);

p1.add(l1); p1.add(l2); l3.setFont(font18); Panel p2=new Panel(); p2.add(l3); p2.setLayout(gl);

Panel p3=new Panel();

l4.setFont(font18);

l5.setFont(font18);

l6.setFont(font18);

l7.setFont(font18);

l8.setFont(font18); p3.add(l4); p3.add(l5); p3.add(l6); p3.add(l7); p3.add(l8); p3.setLayout(cl);

/* Panel p4=new Panel(); Label l11=new Label("ENTERROLLNO");

p4.add(l11); p4.add(tf_entername); p4.add(but_entername); add(p4); add(p1); add(p2); add(p3); */ String arg=e.getActionCommand(); if(e.getSource() instanceof Button) if("FIND".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:stu1","",""); sqlstr="select * from stu1 where ROLLNO="+tf_entername.getText()+""; st=con.createStatement(); ResultSet rs; rs= st.executeQuery(sqlstr);

while(rs.next())
 {
  Panel a1=new Panel();
  l1=new Label("",Label.LEFT);
  l2=new Label("",Label.LEFT);
    l1.setFont(font18);
     l2.setFont(font18);
   a1.setLayout(gl);

  Panel a2=new Panel();
  l3=new Label("",Label.LEFT);
  l3.setFont(font18);
  a2.setLayout(gl);

  Panel a3=new Panel();
  l4=new Label("",Label.LEFT);
  l5=new Label("",Label.LEFT);
  l6=new Label("",Label.LEFT);
  l7=new Label("",Label.LEFT);
  l8=new Label("",Label.LEFT);
  l4.setFont(font18);

   l5.setFont(font18);

   l6.setFont(font18);

   l7.setFont(font18);

    l8.setFont(font18);
   a3.setLayout(cl);

  l1.setText(rs.getString("NAME"));
  l2.setText(""+rs.getInt("ROLLNO"));
  l3.setText(rs.getString("COLG"));
  l4.setText(""+rs.getInt("SUB1"));
  l5.setText(""+rs.getInt("SUB2"));
  l6.setText(""+rs.getInt("SUB3"));
  l7.setText(""+rs.getInt("SUB4"));
  l8.setText(""+rs.getInt("SUB5"));

 a1.add(l1);
 a1.add(l2);

 a2.add(l3);


 a3.add(l4);
 a3.add(l5);
 a3.add(l6);
 a3.add(l7);
 a3.add(l8);

 add(p1);
 add(a1);

 add(p2);
 add(a2);

 add(p3);
 add(a3);
 show();
 }

} catch(ClassNotFoundException se) {

tf_entername.setText("Error : " + se.toString()); }

catch(SQLException se)
{
tf_entername.setText("Error : " + se.toString());
}

}

public void windowClosed(WindowEvent we){} public void windowDeiconified(WindowEvent we){} public void windowIconified(WindowEvent we){} public void windowActivated(WindowEvent we){} public void windowDeactivated(WindowEvent we){} public void windowOpened(WindowEvent we){}

public void windowClosing(WindowEvent we) { while(x>0 && y>0) { setSize(x,y); x=x-d; y=y-d; show(); } dispose();

} }

//class which help in storing records in the database class student extends Frame implements ActionListener,WindowListener

{ public static student st; TextField tf_name=new TextField(20); TextField tf_rollno=new TextField(20); TextField tf_colg=new TextField(20); TextField tf_marks=new TextField(20); TextField tf_sub1=new TextField(4); TextField tf_sub2=new TextField(4); TextField tf_sub3=new TextField(4); TextField tf_sub4=new TextField(4); TextField tf_sub5=new TextField(4);

Label l2=new Label("ROLLNO"); Label l1=new Label("NAME"); Label l3=new Label("MARKS"); Label l4=new Label("COLG"); Label l5=new Label("MARK SHEET"); Label l6=new Label("SUB1"); Label l7=new Label("SUB2"); Label l8=new Label("SUB3"); Label l9=new Label("SUB4"); Label l10=new Label("SUB5"); Button but_add=new Button("ADD"); Button but_edit=new Button("EDIT"); Button but_find=new Button("FIND"); Button but_delete=new Button("DELETE"); Button but_cancel=new Button("CANCEL"); Button ok=new Button("OK"); Dialog dlg; Label msg; int x,y,d;

public student() { super("palce"); addWindowListener(this); setLayout(new GridLayout(6,1)); setBackground(Color.yellow); setVisible(true); addmenu(); x=550; y=450; d=12; setSize(x,y); show(); }

void addmenu() { //GridLayout gl=new GridLayout(); Panel p1=new Panel(); p1.add(l1); p1.add(tf_name);

p1.add(l2); p1.add(tf_rollno);

Panel p2=new Panel(); p2.add(l5); Panel p3=new Panel(); p3.add(but_add); p3.add(but_find); p3.add(but_cancel); p3.add(but_edit); p3.add(but_delete);

Panel p4=new Panel(); //p4.add(l3); p4.add(l6); p4.add(l7); p4.add(l8); p4.add(l9); p4.add(l10);

Panel p8=new Panel(); p8.add(tf_sub1); p8.add(tf_sub2); p8.add(tf_sub3); p8.add(tf_sub4); p8.add(tf_sub5);

Panel p5=new Panel(); p5.add(l4); p5.add(tf_colg);

add(p2); add(p1); add(p5); add(p4); add(p8); add(p3); but_add.addActionListener(this); but_cancel.addActionListener(this); but_find.addActionListener(this); but_delete.addActionListener(this); but_edit.addActionListener(this); ok.addActionListener(this); //Dialog for confirmation

 dlg=new Dialog(this,"Inventory Management System",false);
 dlg.setLayout(new GridLayout(2,1));
 dlg.setSize(100,100);
 dlg.setLocation(200,100);
 ok.setSize(50,50);
 msg=new Label("Record Updated");
 dlg.add(msg);
 dlg.add(ok);

} public void actionPerformed(ActionEvent e) { String arg=e.getActionCommand(); //ADDBUTTON if(e.getSource() instanceof Button) if("ADD".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:stu1","",""); Statement st;

String sqlStr; sqlStr="insert into stu1(NAME,ROLLNO,COLG,SUB1,SUB2,SUB3,SUB4,SUB5)values('"+tfname.getText()+"',"+tfrollno.getText()+",'"+tfcolg.getText()+"',"+tfsub1.getText()+","+tfsub2.getText()+","+tfsub3.getText()+","+tfsub4.getText()+","+tfsub5.getText()+")"; st=con.createStatement(); st.executeUpdate(sqlStr); } catch(ClassNotFoundException se) { // tf_name.setText("Error : " + se.toString()); msg.setText("ERROR"); dlg.show(); } catch(SQLException se) { // tf_name.setText("Error : " + se.toString()); msg.setText("ENTER TEXTFIELD"); dlg.show(); }

//OK button

if ( e.getSource() instanceof Button)
    if ("OK".equals(arg))
    { dlg.dispose();
    }

//CANCEL if(e.getSource() instanceof Button) if("CANCEL".equals(arg))

{
tf_name.setText("");
tf_rollno.setText("");
tf_colg.setText("");
tf_sub1.setText("");
tf_sub2.setText("");
tf_sub3.setText("");
tf_sub4.setText("");
 tf_sub5.setText("");
 }

//FIND if(e.getSource() instanceof Button) if("FIND".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:stu1","",""); Statement st; String sqlstr; sqlstr="select * from stu1 where ROLLNO ="+tf_rollno.getText()+""; st=con.createStatement(); ResultSet rs; rs=st.executeQuery(sqlstr); rs.next(); tf_name.setText(""+rs.getString("NAME")); tf_colg.setText(""+rs.getString("COLG")); tf_sub1.setText(""+rs.getInt("SUB1")); tf_sub2.setText(""+rs.getInt("SUB2")); tf_sub3.setText(""+rs.getInt("SUB3")); tf_sub4.setText(""+rs.getInt("SUB4")); tf_sub5.setText(""+rs.getInt("SUB5")); } catch(ClassNotFoundException se) { msg.setText("RECORD NOT FOUND"); dlg.show();

// tf_name.setText("Error : " + se.toString()); } catch(SQLException se) { msg.setText("RECORD NOT FOUND"); dlg.show(); //tf_name.setText("Error : " + se.toString()); } //DELETE if(e.getSource() instanceof Button) if("DELETE".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:stu1","",""); Statement st; String sqlstr; sqlstr="delete * from stu1 where ROLLNO="+tf_rollno.getText()+""; st=con.createStatement(); st.executeUpdate(sqlstr); tf_name.setText(""); tf_colg.setText(""); tf_sub1.setText(""); tf_sub2.setText(""); tf_sub3.setText(""); tf_sub4.setText(""); tf_sub5.setText("");

tf_rollno.setText(""); msg.setText("RECORD DELETED"); dlg.show();

} catch(ClassNotFoundException se) { tf_name.setText("Error : " + se.toString()); } catch(SQLException se) { tf_name.setText("Error : " + se.toString()); }

//EDIT if(e.getSource() instanceof Button) if("EDIT".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:stu1","",""); Statement st; String sqlstr; sqlstr="update stu1 set NAME='"+tfname.getText()+"',COLG='"+tfcolg.getText()+"',SUB1="+tfsub1.getText()+",SUB2="+tfsub2.getText()+",SUB3="+tfsub3.getText()+",SUB4="+tfsub4.getText()+",SUB5="+tfsub5.getText()+" where ROLLNO="+tfrollno.getText()+""; st=con.createStatement(); st.executeUpdate(sqlstr); msg.setText("RECORD UPDATED"); dlg.show(); } catch(ClassNotFoundException se) {

tf_name.setText("Error : " + se.toString()); } catch(SQLException se) {

tf_name.setText("Error : " + se.toString()); } } public void windowClosed(WindowEvent we){} public void windowDeiconified(WindowEvent we){} public void windowIconified(WindowEvent we){} public void windowActivated(WindowEvent we){} public void windowDeactivated(WindowEvent we){} public void windowOpened(WindowEvent we){} public void windowClosing(WindowEvent we) { while(x>0 && y>0) { setSize(x,y); x=x-d; y=y-d; show(); } dispose(); }

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
java code
java code  write a java code to convert hindi to english using arrays
Advertisements
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE
java code
java code  what is the code to turn off my pc through java program
java code
java code  hi any one please tell me the java code to access any link i mean which method of which class is used to open any link in java program
java code
java code  write a java code for finding a string in partiular position in a delimited text file and replace the word with the values given by user and write the file in new location
java code
java code  sir how to merge the cells in excel using java code please help me and also how to make the text placed in the cell to be center
java code
java code  sir how to merge the cells in excel using java code please help me and also how to make the text placed in the cell to be center
java code
java code  need java code for chart or graph which compare the performance of aprior algorithm and coherent rule algorithm.plz any one help me out
java code
java code  I need the java code that would output the following: HARDWARE ITEMS CODE DESCRIPTION UNIT PRICE K16 Wood screws,brass,20mm $7.75 D24 Wood glue,clear,1 liter $5.50 M93
Java code
Java code   Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes
java code
java code  develop a banking system in java
java code
java code  HOW TO PRINT 1 TO 100 WITHOUT USING CONDITIONAL,ANY LOOP AND ARRAY IN JAVA AND C.URGENT SIR PLZ  Hi, You can use following code: class MyClass { public static void main(String[] args) { int
java code
java code  how to extract html tags using java
java code
java code  int g() { System.out.println("Inside method g"); int h() { System.out.println("Inside method h"); } } Find the error in the following... cannot define a method inside another method. Anyways, we have modified your code
Java code
Java code  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any... the following code: import java.util.*; import java.text.*; class NumberProgram
java code
java code  what is meaning bufferedreader
java code
java code  what is meaning bufferedreader
Java code
Java code  An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus...; Hi Friend, Try the following code: import java.util.*; import
Java code
Java code   Create a calculator class which will have methods add, multiply, divide & subtract   Hi Friend, Try the following code: class Calculation{ public int add(int a,int b){ return a+b
java code
java code  i want HSVcolor descriptor for color image in java coding
java code
java code  hi, Can any one tell me " How to read the data which is present om an image in java
Java Code
Java Code  Write a java program, which creates multiple threads. Each thread performs add/delete/update operations on an ArrayList simultaneously
java code
java code  I am beginer in java my question is how can i fill data from mysql database to jcombobox using netbeans
Java code
Java code  Create a class called Student which has the following methods: i. Average: which would accept marks of 3 examinations & return... & returns the name.   Hi Friend, Try the following code: import
Java code
Java code  Create a Bank class with methods deposit & withdraw. The deposit method would accept attributes amount & balance & returns....   Hi Friend, Try the following code: import javax.swing.*; class
Java code
Java code   Create an Employee class which has methods netSalary which would accept salary & tax as arguments & returns the netSalary which... the following code: import java.util.*; class Employee { static Scanner input=new
java code
java code  An employee _id consist of 5 digits is stored in a string variable strEmpid. Now Mr.Deb wants to store this Id in Integer type to IntEmpid. write Java statements to do
java code
java code  input any word ie risk,resul is-- r ri ris risk
java code
java code  Create a calculator class which will have methods add, multiply, divide & subtract
java code
java code   Develop a program that accepts the area of a square and will calculate its perimeter
 

 

 

DMCA.com