Hi..Iam using theNet beans ide for the code below:
import java.awt.event.*;
import java.sql.*;
public class BarcodeReader extends JFrame implements ActionListener {
public BarcodeReader() {
initComponents();
nb.addActionListener(this);
}
public BarcodeReader() {
initComponents();
nb.addActionListener(this);
tble.addActionListener(this);
eb.addActionListener(this);
jButton1.addActionListener(this);
jButton2.addActionListener(this);
}
public void jdbcConnect(){
Connection con=null;
String url = "jdbc:mysql://localhost:3306/";
String db = "database";
String driver = "com.mysql.jdbc.Driver";
String user = "unam";
String pass = "pwd";
try{
con=DriverManager.getConnection(url + db, user, pass);
con.setAutoCommit(false);
Statement stmt=con.createStatement();
Class.forName(driver);
stmt.execute("INSERT into machine(barcode) VALUES ('"+s+"')");
con.commit();
con.close();
System.out.println("Connection is closed...");
}catch (Exception ex) {
System.out.println(ex);
}}
//actionlistener for the button in new machine
public void actionPerformed(ActionEvent e){
try{
if(e.getSource()==nb){
jdbcConnect();
stmt.executeUpdate("INSERT into machine(mname) values "+jTextField1.getText()+"'");
}}catch (Exception ex) {
System.out.println(ex);
}new NewJFrame().setVisible(true);
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BarcodeReader().setVisible(true);
}
});
}
In the actionPerformed method i'm gettin the erro cannot find variable "stmt".
But i've initialized in the jdbcConnect() method. wth is the pblm here??Plz excuse for the untidy indendtns..
Bookmarks