database
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   nawaray_ms
Posted On:   Monday, October 6, 2003 07:16 AM

helloo... i have this code that doesn't work with me ... i have an application which has two text fields , and when i open the application i want to enter in the text fields and then when i click on the next button i want the fields that were entered to be stored in my table.. import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Datas extends JFrame implements ActionListener { JTextField id; JTextField name; JButton next; JButton addnew; JPanel p; static ResultSet res; static Connection conn;    More>>

helloo...


i have this code that doesn't work with me ...

i have an application which has two text fields , and when i open the application i want to enter in the text fields and then when i click on the next button i want the fields that were entered to be stored in my table..





import java.sql.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class Datas extends JFrame implements ActionListener {


JTextField id;

JTextField name;

JButton next;

JButton addnew;

JPanel p;

static ResultSet res;

static Connection conn;

static Statement stat;


public Datas() {

super("Our Application");

Container c = getContentPane();

c.setLayout(new GridLayout(5,1));

id = new JTextField(20);

name = new JTextField(20);

next = new JButton("Next");

p = new JPanel();

c.add(new JLabel("Customer ID",JLabel.CENTER));

c.add(id);

c.add(new JLabel("Customer Name",JLabel.CENTER));

c.add(name);

c.add(p);

p.add(next);

next.addActionListener(this);

pack();

setVisible(true);

addWindowListener(new WIN());


}

public static void main(String args[]) {

Datas d = new Datas();

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn = DriverManager.getConnection("jdbc:odbc:cust"); // cust is the DSNName


stat = conn.createStatement();

stat.executeUpdate(

"INSERT INTO Customers " +

"VALUES (10, 'fatima')");

res = stat.executeQuery("Select * from Customers");
// Customers is the table name

res.next();


}

catch(Exception e) {

System.out.println("Error" +e);

}

d.showRecord(res);

}

public void actionPerformed(ActionEvent e) {

if(e.getSource() == next) {

try {

res.next();

}

catch(Exception ee) {}

showRecord(res);

}

}


public void showRecord(ResultSet res) {

try {

id.setText(res.getString(1));

name.setText(res.getString(2));

}

catch(Exception e) {}


}//end of the main


//Inner class WIN implemented

class WIN extends WindowAdapter {

public void windowClosing(WindowEvent w) {

JOptionPane jop = new JOptionPane();

jop.showMessageDialog(null,"Database","Thanks",JOptionPane.QUESTION_MESSAGE);

}


} //end of the class

}



thankxx

   <<Less

Re: database

Posted By:   Benoit_Quintin  
Posted On:   Monday, October 6, 2003 01:58 PM

Well, I'm not about to compile and run this coe, why don't you explain what the problem is ? (I mean a little less vague that it doesn't work)
e.g. Does it compile ?
Does it run ?
Is there a stack trace and if so what is it ?
etc.
About | Sitemap | Contact