Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-09-2009
Member
 
Join Date: Jul 2009
Posts: 8
Exclamation Java Swing and MySQL

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..
Reply With Quote
  #2  
Old 22-09-2009
Member
 
Join Date: Aug 2009
Posts: 12
Re: Java Swing and MySQL

Can you tell me why are you initializing the "Statement stmt=con.createStatement();" In the Try { block }?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Java Swing and MySQL"
Thread Thread Starter Forum Replies Last Post
Applets V/s Swing in JAVA "Dritan" Software Development 3 14-12-2010 09:04 AM
Print in java using Swing Sheenas Software Development 3 18-11-2009 09:50 AM
drawPolygon in java Swing? JagdishP Software Development 3 07-08-2009 11:33 PM
Message Box example for Java Swing Visala28 Software Development 3 31-07-2009 05:30 PM
Java swing help with repaint() grudge Software Development 4 23-07-2009 03:41 PM


All times are GMT +5.5. The time now is 03:45 PM.