Results 1 to 3 of 3
- 11-19-2011, 02:03 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
problem with inserting into table
AIM:to take the input from the user and insert it into the specified table.
i tried the following code for my project but i was not successful in doing so
plz help me
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class xyz extends JFrame implements ActionListener
{
JLabel lbl,lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7;
JButton b1,b2,b3;;
JComboBox box1,box2,box3,box4,box5;
JTextField tf=new JTextField();
PreparedStatement ps1;
PreparedStatement ps2;
PreparedStatement ps3;
PreparedStatement ps4;
PreparedStatement ps5;
PreparedStatement ps6;
Connection con,con1,con2,con3,con4,con5,con6;
xyz()
{
Container c=this.getContentPane();
this.setLayout(null);
c.setBackground(Color.cyan);
lbl=new JLabel("ENTER MCA1 ATTENDANCE");
lbl.setFont(new Font("Helvetica",Font.BOLD,34));
lbl.setForeground(Color.red);
lbl1=new JLabel("SELECT DAY");
lbl1.setFont(new Font("Helvetica",Font.BOLD,13));
lbl1.setForeground(Color.red);
lbl2=new JLabel("MONTH");
lbl2.setFont(new Font("Helvetica",Font.BOLD,13));
lbl2.setForeground(Color.red);
lbl3=new JLabel("YEAR");
lbl3.setFont(new Font("Helvetica",Font.BOLD,13));
lbl3.setForeground(Color.red);
lbl4=new JLabel("SELECT SUBJECT");
lbl4.setFont(new Font("Helvetica",Font.BOLD,13));
lbl4.setForeground(Color.red);
lbl5=new JLabel("SELECT PERIOD NUM");
lbl5.setFont(new Font("Helvetica",Font.BOLD,13));
lbl5.setForeground(Color.red);
lbl6=new JLabel("ENTER ABSENTEE NUMBERS");
lbl6.setFont(new Font("Helvetica",Font.BOLD,25));
lbl6.setForeground(Color.red);
box1=new JComboBox();
box2=new JComboBox();
box3=new JComboBox();
box4=new JComboBox();
box5=new JComboBox();
box1.addItem("1");box1.addItem("2");box1.addItem(" 3");box1.addItem("4");box1.addItem("5");box1.addIt em("6");
box1.addItem("7");box1.addItem("8");box1.addItem(" 9");box1.addItem("10");box1.addItem("11");box1.add Item("12");
box1.addItem("13");box1.addItem("14");box1.addItem ("15");box1.addItem("16");box1.addItem("17");box1. addItem("18");
box1.addItem("19");box1.addItem("20");box1.addItem ("21");box1.addItem("22");box1.addItem("23");box1. addItem("24");
box1.addItem("25");box1.addItem("26");box1.addItem ("27");box1.addItem("28");box1.addItem("29");box1. addItem("30");
box1.addItem("31");
box2.addItem("JAN");box2.addItem("FEB");box2.addIt em("MAR");box2.addItem("APR");box2.addItem("MAY") ;
box2.addItem("JUN");box2.addItem("JUL");box2.addIt em("AUG");box2.addItem("SEP");box2.addItem("OCT") ;
box2.addItem("NOV");box2.addItem("DEC");
box3.addItem("2011");box3.addItem("2012");box3.add Item("2013");box3.addItem("2014");box3.addItem("20 15");
box3.addItem("2016");box3.addItem("2017");box3.add Item("2018");box3.addItem("2019");box3.addItem("20 20");
box4.addItem("JAVA");box4.addItem("UNIX");box4.add Item("CN");box4.addItem("SE");box4.addItem("OB");
box4.addItem("JAVA LAB");box4.addItem("UNIX LAB");
box5.addItem("1");box5.addItem("2");box5.addItem(" 3");box5.addItem("4");box5.addItem("5");box5.addIt em("6");
b1=new JButton("SUBMIT");
b2=new JButton("BACK");
b3=new JButton("HOME");
lbl.setBounds(250,50,500,40);
lbl1.setBounds(200,150,100,20);
box1.setBounds(290,150,40,20);
lbl2.setBounds(380,150,50,20);
box2.setBounds(440,150,50,20);
lbl3.setBounds(580,150,50,20);
box3.setBounds(630,150,60,20);
lbl4.setBounds(200,200,150,20);
box4.setBounds(330,200,70,20);
lbl5.setBounds(450,200,150,20);
box5.setBounds(600,200,40,20);
lbl6.setBounds(300,250,500,20);
tf.setBounds(300,350,200,20);
b1.setBounds(450,600,100,30);
b2.setBounds(300,600,100,30);
b3.setBounds(600,600,100,30);
c.add(lbl);
c.add(lbl1);
c.add(lbl2);
c.add(lbl3);
c.add(lbl4);
c.add(lbl5);
c.add(lbl6);
c.add(box1);
c.add(box2);
c.add(box3);
c.add(box4);
c.add(box5);
c.add(b1);
c.add(b2);
c.add(b3);
c.add(tf);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
void getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con1=DriverManager.getConnection("jdbc:odbc:mca211 ","system","system");
ps1=con1.prepareStatement("insert into mca211 values(?,?,?)");
con2=DriverManager.getConnection("jdbc:odbc:mca212 ","system","system");
ps2=con2.prepareStatement("insert into mca212 values(?,?,?)");
con3=DriverManager.getConnection("jdbc:odbc:mca213 ","system","system");
ps3=con3.prepareStatement("insert into mca213 values(?,?,?)");
con4=DriverManager.getConnection("jdbc:odbc:mca214 ","system","system");
ps4=con4.prepareStatement("insert into mca214 values(?,?,?)");
con5=DriverManager.getConnection("jdbc:odbc:mca215 ","system","system");
ps5=con5.prepareStatement("insert into mca215 values(?,?,?)");
con6=DriverManager.getConnection("jdbc:odbc:mca216 ","system","system");
ps6=con6.prepareStatement("insert into mca216 values(?,?,?)");
}
catch(ClassNotFoundException e)
{
}
catch(SQLException e)
{
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
String d=(String)box1.getSelectedItem();
String m=(String)box2.getSelectedItem();
String y=(String)box3.getSelectedItem();
String sub=(String)box4.getSelectedItem();
String pno=(String)box5.getSelectedItem();
String temp="-";
String date=d+m+y+temp;
String num=(String)tf.getText();
try
{
if(pno=="1")
{
ps1.setString(1,date);
ps1.setString(2,sub);
ps1.setString(3,num);
ps1.executeUpdate();
}
else if(pno=="2")
{
ps2.setString(1,date);
ps2.setString(2,sub);
ps2.setString(3,num);
ps2.executeUpdate();
}
else if(pno=="3")
{
ps3.setString(1,date);
ps3.setString(2,sub);
ps3.setString(3,num);
ps3.executeUpdate();
}
else if(pno=="4")
{
ps4.setString(1,date);
ps4.setString(2,sub);
ps4.setString(3,num);
ps4.executeUpdate();
}
else if(pno=="5")
{
ps5.setString(1,date);
ps5.setString(2,sub);
ps5.setString(3,num);
ps5.executeUpdate();
}
else if(pno=="6")
{
ps6.setString(1,date);
ps6.setString(2,sub);
ps6.setString(3,num);
ps6.executeUpdate();
}
}
catch(SQLException se)
{
}
}
if(ae.getSource()==b3)
{
framedemo f=new framedemo();
f.setSize(1050,750);
f.setTitle("ATTENDANCE MANAGEMENT SYSTEM");
this.dispose();
f.setVisible(true);
}
if(ae.getSource()==b2)
{
enterat f=new enterat();
f.setSize(1050,750);
f.setTitle("ENTER ATTENDANCE");
this.dispose();
f.setVisible(true);
}
}
public static void main(String args[])throws Exception
{
xyz m=new xyz();
m.setTitle("enter attendance");
m.setSize(1050,750);
m.setVisible(true);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
- 11-19-2011, 03:44 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: problem with inserting into table
One post is enough
http://www.java-forums.org/database/...nto-table.html
And suggested reading: How To Ask Questions The Smart Way
-
Re: problem with inserting into table
I see that you have frequently multiposted the same question in these forums more than once. Please re-read the forum rules that you agreed to on joining us and please abide by them. Also you'll want to take the time to reply to folks who have taken the time to offer help in your previous threads. You seem to be ignoring them by not at least thanking them for the time that they've taken to consider your problem.
Similar Threads
-
problem with inserting into table
By pardhu in forum JDBCReplies: 1Last Post: 11-19-2011, 04:42 AM -
Help on inserting into table
By ShinTec in forum JDBCReplies: 4Last Post: 06-08-2010, 09:26 AM -
Inserting a Table in a TextFile?
By Keerti in forum Advanced JavaReplies: 5Last Post: 11-19-2008, 04:31 PM -
Inserting current date into a DB table
By Java Tip in forum Java TipReplies: 0Last Post: 02-15-2008, 08:38 AM -
Inserting into a table (Example)
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:25 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks