import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class AddNewItem extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4;
JTextField t1,t2,t3,t4;
JButton b1,b2,b3;
AddNewItem()
{
l1=new JLabel("Product Name ");
l2=new JLabel("Product Price ");
l3=new JLabel("Quantity ");
l4=new JLabel("Product Type ");
t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("Clear");
b2=new JButton("Save ");
b3=new JButton("Close");
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Error :: "+cnfe.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:Invent");
Statement st=con.createStatement();
String qry="Insert into prodmaster(prodnm,price,qty,prodtype,mfrdate) values('"+t1.getText()+"',"+t2.getText()+","+t3.getText()+",'"+t4.getText()+"',date())";
int ans=st.executeUpdate(qry);
if(ans==1)
System.out.println("Data Saved... ");
}
catch(SQLException se)
{
System.out.println("Problems :: "+se.getMessage());
}
}
}
public static void main(String ar[])
{
AddNewItem ani=new AddNewItem();
ani.setSize(300,250);
ani.setVisible(true);
}
}
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class AddNewItem extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4;
JTextField t1,t2,t3,t4;
JButton b1,b2,b3;
AddNewItem()
{
l1=new JLabel("Product Name ");
l2=new JLabel("Product Price ");
l3=new JLabel("Quantity ");
l4=new JLabel("Product Type ");
t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("Clear");
b2=new JButton("Save ");
b3=new JButton("Close");
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Error :: "+cnfe.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:Invent");
Statement st=con.createStatement();
String qry="Insert into prodmaster(prodnm,price,qty,prodtype,mfrdate) values('"+t1.getText()+"',"+t2.getText()+","+t3.getText()+",'"+t4.getText()+"',date())";
int ans=st.executeUpdate(qry);
if(ans==1)
System.out.println("Data Saved... ");
}
catch(SQLException se)
{
System.out.println("Problems :: "+se.getMessage());
}
}
}
public static void main(String ar[])
{
AddNewItem ani=new AddNewItem();
ani.setSize(300,250);
ani.setVisible(true);
}
}
No comments:
Post a Comment