Results 1 to 4 of 4
Thread: data base connectivity
- 02-20-2010, 07:22 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 1
- Rep Power
- 0
data base connectivity
:confused:
hello friends! this a program which adds two number and store the result in database, but error.... plz solve
plz solve this problem
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class calc1 extends JFrame implements ActionListener {
Container ctn = getContentPane();
JLabel lbl1,lbl2,lbl3;
JTextField txt1,txt2,txt3;
JButton btn;
calc1(){
// Container ctn = getContentPane();
this.setLayout(null);
lbl1 = new JLabel("ENTER THE NO.1");
lbl2 = new JLabel("ENTER THE NO.2");
lbl3 = new JLabel("SUM");
txt1 = new JTextField(20);
txt2 = new JTextField(20);
txt3 = new JTextField(20);
btn = new JButton("ADD");
btn.addActionListener(this);
Color c1 = new Color(235,34,111);
ctn.setBackground(c1);
lbl1.setBounds(50,50,100,30);
txt1.setBounds(170,50,100,30);
lbl2.setBounds(50,100,100,30);
txt2.setBounds(170,100,100,30);
btn.setBounds(100,250,100,30);
lbl3.setBounds(50,200,100,30);
txt3.setBounds(170,200,100,30);
txt1.setBackground(Color.WHITE);
txt2.setBackground(Color.WHITE);
txt3.setEditable(false);
this.setSize(500,500);
this.setVisible(true);
this.setResizable(false);
ctn.add(lbl1);
ctn.add(lbl2);
ctn.add(lbl3);
ctn.add(txt1);
ctn.add(txt2);
ctn.add(txt3);
ctn.add(btn);
}
public void actionPerformed(ActionEvent e){
int a = Integer.parseInt(txt1.getText());
int b = Integer.parseInt(txt2.getText());
int c= a+b;
txt3.setText(String.valueOf(c));
if(e.getSource()==btn){
ctn.setBackground(Color.PINK);
}
int n = Integer.parseInt(txt3.getText());
try {
class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:calc");
Statement st = con.createStatement();
String sql="insert into table1 "+"col1"+"values"+"n";
st.executeUpdate(sql);
}catch (SQLException ee){
System.out.println(ee.toString());
}
}
public static void main (String[] args) {
calc1 c = new calc1();
}
}Last edited by zeeshan; 02-21-2010 at 06:15 PM.
-
- 02-21-2010, 01:09 AM #3
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
Your jdbc code is no where. It has be within some method but since u closed the braces just before jdbc code, it doesn't belong to any method. And database interaction shd happen after certain button is clicked which is also no there. May be the braces after ctn.setBackground(Color.PINK); should't b there.
- 02-21-2010, 01:11 AM #4
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
Similar Threads
-
data structure and data base??
By ahmed13 in forum Advanced JavaReplies: 8Last Post: 03-27-2009, 05:48 AM -
how to store the data in data base
By eclipse3.4ide in forum New To JavaReplies: 5Last Post: 02-03-2009, 04:25 AM -
error while retrieving data from data base
By kirtesh4u in forum New To JavaReplies: 5Last Post: 11-15-2008, 04:10 PM -
Problems when I try to connect to data base
By gabriel in forum JDBCReplies: 1Last Post: 08-06-2007, 05:38 PM -
Connection to data base
By Daniel in forum JDBCReplies: 2Last Post: 06-07-2007, 04:55 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks