tybca slip 94
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class slip94 extends JFrame implements ActionListener
{
JLabel id,cname,address,year;
JTextField t1,t2,t3,t4;
JButton b;
Connection con;
PreparedStatement ps;
slip94()
{
try
{
setLayout(null);
t1=new JTextField();
t1.setSize(120,30);
t1.setLocation(250,50);
id=new JLabel(" Enter College id");
id.setSize(120,20);
id.setLocation(110,50);
t2=new JTextField();
t2.setSize(120,30);
t2.setLocation(250,100);
cname=new JLabel("Enter the College name=");
cname.setSize(150,20);
cname.setLocation(110,100);
t3=new JTextField();
t3.setSize(120,30);
t3.setLocation(250,150);
address=new JLabel("enter the college Address is");
address.setSize(200,20);
address.setLocation(100,150);
t4=new JTextField();
t4.setSize(120,30);
t4.setLocation(250,200);
year=new JLabel("enter the year");
year.setSize(100,20);
year.setLocation(100,200);
add(id);
add(cname);
add(address);
add(year);
add(t1);
add(t2);
add(t3);
add(t4);
b=new JButton("Submit");
b.setSize(100,30);
b.setLocation(150,250);
b.addActionListener(this);
setSize(600,700);
setLocation(100,100);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(b);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:emp");
ps=con.prepareStatement("insert into college values(?,?,?,?)");
}
catch(Exception e)
{
System.out.print(e.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
try
{
if(!t1.getText().equals("")&&!t2.getText().equals("")&&!t3.getText().equals("")&&!t4.getText().equals(""))
{
int n= Integer.parseInt(t1.getText());
int v=0;
String str=t4.getText();
/*
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='-')
{
v++;
}
}
*/
ps.setInt(1,n);
ps.setString(2,t2.getText());
ps.setString(3,t3.getText());
ps.setString(4,t4.getText());
int cnt=ps.executeUpdate();
if(cnt==1)
{
JOptionPane.showMessageDialog(null,"Record inserted Succefully");
}
else
{
JOptionPane.showMessageDialog(null,"Record inserted UN-Succefully");
}
}
else
{
JOptionPane.showMessageDialog(null,"Some TextField is empty");
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error occured by Id ");
}
}
public static void main(String args[])
{
slip94 ob=new slip94();
}
}
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class slip94 extends JFrame implements ActionListener
{
JLabel id,cname,address,year;
JTextField t1,t2,t3,t4;
JButton b;
Connection con;
PreparedStatement ps;
slip94()
{
try
{
setLayout(null);
t1=new JTextField();
t1.setSize(120,30);
t1.setLocation(250,50);
id=new JLabel(" Enter College id");
id.setSize(120,20);
id.setLocation(110,50);
t2=new JTextField();
t2.setSize(120,30);
t2.setLocation(250,100);
cname=new JLabel("Enter the College name=");
cname.setSize(150,20);
cname.setLocation(110,100);
t3=new JTextField();
t3.setSize(120,30);
t3.setLocation(250,150);
address=new JLabel("enter the college Address is");
address.setSize(200,20);
address.setLocation(100,150);
t4=new JTextField();
t4.setSize(120,30);
t4.setLocation(250,200);
year=new JLabel("enter the year");
year.setSize(100,20);
year.setLocation(100,200);
add(id);
add(cname);
add(address);
add(year);
add(t1);
add(t2);
add(t3);
add(t4);
b=new JButton("Submit");
b.setSize(100,30);
b.setLocation(150,250);
b.addActionListener(this);
setSize(600,700);
setLocation(100,100);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(b);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:emp");
ps=con.prepareStatement("insert into college values(?,?,?,?)");
}
catch(Exception e)
{
System.out.print(e.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
try
{
if(!t1.getText().equals("")&&!t2.getText().equals("")&&!t3.getText().equals("")&&!t4.getText().equals(""))
{
int n= Integer.parseInt(t1.getText());
int v=0;
String str=t4.getText();
/*
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='-')
{
v++;
}
}
*/
ps.setInt(1,n);
ps.setString(2,t2.getText());
ps.setString(3,t3.getText());
ps.setString(4,t4.getText());
int cnt=ps.executeUpdate();
if(cnt==1)
{
JOptionPane.showMessageDialog(null,"Record inserted Succefully");
}
else
{
JOptionPane.showMessageDialog(null,"Record inserted UN-Succefully");
}
}
else
{
JOptionPane.showMessageDialog(null,"Some TextField is empty");
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Error occured by Id ");
}
}
public static void main(String args[])
{
slip94 ob=new slip94();
}
}
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.