Results 1 to 3 of 3

Thread: Help needed.

  1. #1
    necro-1000 is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Default Help needed.

    First of all hi, I hope I am posting in the right forum hehe.

    Well, I am trying to write a small program that connected to an online database using mySQL. By any chance does any1 know what is causing it?

    These errors come up when I try to press the add button to add new information to the database.

    I can also post the code that is making the program crash too,

    Thanks for any help!

    init:
    deps-jar:
    Compiling 1 source file to J:\Java Assignment\HotelReservationSystem\build\classes
    compile-single:
    run-single:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at DB.DBRoutines.loadDatabaseDriver(DBRoutines.java:4 9)
    at DB.DBRoutines.<init>(DBRoutines.java:39)
    at System.HotelGUI.btnClientAddMouseClicked(HotelGUI. java:171)
    at System.HotelGUI.access$000(HotelGUI.java:16)
    at System.HotelGUI$1.mouseClicked(HotelGUI.java:77)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEvent Multicaster.java:212)
    at java.awt.Component.processMouseEvent(Component.jav a:5520)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3135)
    at java.awt.Component.processEvent(Component.java:528 2)
    at java.awt.Container.processEvent(Container.java:196 6)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3984)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2024)
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3901)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1791 )
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager .java:545)
    at java.sql.DriverManager.getConnection(DriverManager .java:171)
    at DB.DBRoutines.connect(DBRoutines.java:62)
    at System.HotelGUI.btnClientAddMouseClicked(HotelGUI. java:172)
    at System.HotelGUI.access$000(HotelGUI.java:16)
    at System.HotelGUI$1.mouseClicked(HotelGUI.java:77)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEvent Multicaster.java:212)
    at java.awt.Component.processMouseEvent(Component.jav a:5520)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3135)
    at java.awt.Component.processEvent(Component.java:528 2)
    at java.awt.Container.processEvent(Container.java:196 6)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3984)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2024)
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3901)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1791 )
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at System.HotelGUI.btnClientAddMouseClicked(HotelGUI. java:177)
    at System.HotelGUI.access$000(HotelGUI.java:16)
    at System.HotelGUI$1.mouseClicked(HotelGUI.java:77)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEvent Multicaster.java:212)
    at java.awt.Component.processMouseEvent(Component.jav a:5520)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3135)
    at java.awt.Component.processEvent(Component.java:528 2)
    at java.awt.Container.processEvent(Container.java:196 6)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3984)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2024)
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3901)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1791 )
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
    BUILD SUCCESSFUL (total time: 1 minute 27 seconds)

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    necro, welcome to Java Forums!

    Let's see some code. :)

    See you around!
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    necro-1000 is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Default

    Here's the code, and thanks for the help!

    /*
    * HotelGUI.java
    *
    * Created on 07 January 2008, 10:43
    */

    package System;
    import DB.DBRoutines;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import javax.swing.JOptionPane;
    /**
    *
    * @author andrpors
    */
    public class HotelGUI extends javax.swing.JFrame {

    /** Creates new form HotelGUI */
    public HotelGUI() {
    initComponents();
    choClientType.add("");
    choClientType.add("Business");
    choClientType.add("Couple");
    choClientType.add("Family");
    choClientType.add("VIP");
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    HotelPanes = new javax.swing.JTabbedPane();
    ClientTab = new javax.swing.JPanel();
    txtClientId = new javax.swing.JTextField();
    lblClientId = new javax.swing.JLabel();
    txtClientName = new javax.swing.JTextField();
    lblClientName = new javax.swing.JLabel();
    txtClientSurname = new javax.swing.JTextField();
    lblClientSurname = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    txtClientAddress = new javax.swing.JEditorPane();
    lblClientAddress = new javax.swing.JLabel();
    txtClientTel = new javax.swing.JTextField();
    lblClientTelephone = new javax.swing.JLabel();
    lblClientMobile = new javax.swing.JLabel();
    txtClientMobile = new javax.swing.JTextField();
    choClientType = new java.awt.Choice();
    lblClientType = new javax.swing.JLabel();
    btnClientAdd = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    setResizable(false);

    lblClientId.setText("Client ID");

    lblClientName.setText("Name");

    lblClientSurname.setText("Surname");

    jScrollPane1.setViewportView(txtClientAddress);

    lblClientAddress.setText("Address");

    lblClientTelephone.setText("Telephone");

    lblClientMobile.setText("Mobile");

    lblClientType.setText("Client Type");

    btnClientAdd.setText("Add");
    btnClientAdd.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    btnClientAddMouseClicked(evt);
    }
    });

    org.jdesktop.layout.GroupLayout ClientTabLayout = new org.jdesktop.layout.GroupLayout(ClientTab);
    ClientTab.setLayout(ClientTabLayout);
    ClientTabLayout.setHorizontalGroup(
    ClientTabLayout.createParallelGroup(org.jdesktop.l ayout.GroupLayout.LEADING)
    .add(ClientTabLayout.createSequentialGroup()
    .add(38, 38, 38)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
    .add(ClientTabLayout.createSequentialGroup()
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.TRAILING)
    .add(lblClientSurname)
    .add(lblClientName)
    .add(lblClientTelephone)
    .add(lblClientAddress)
    .add(lblClientMobile)
    .add(lblClientType))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.TRAILING, false)
    .add(org.jdesktop.layout.GroupLayout.LEADING, txtClientMobile)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
    .add(txtClientName)
    .add(txtClientSurname, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
    .add(txtClientTel)
    .add(org.jdesktop.layout.GroupLayout.LEADING, choClientType, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .add(18, 18, 18)
    .add(btnClientAdd))
    .add(ClientTabLayout.createSequentialGroup()
    .add(lblClientId)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(txtClientId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)))
    .addContainerGap(15, Short.MAX_VALUE))
    );
    ClientTabLayout.setVerticalGroup(
    ClientTabLayout.createParallelGroup(org.jdesktop.l ayout.GroupLayout.LEADING)
    .add(ClientTabLayout.createSequentialGroup()
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
    .add(ClientTabLayout.createSequentialGroup()
    .addContainerGap()
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
    .add(lblClientId)
    .add(txtClientId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED, 82, Short.MAX_VALUE)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, ClientTabLayout.createSequentialGroup()
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
    .add(lblClientTelephone)
    .add(txtClientTel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
    .add(txtClientMobile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(lblClientMobile)))
    .add(org.jdesktop.layout.GroupLayout.TRAILING, ClientTabLayout.createSequentialGroup()
    .add(lblClientAddress)
    .add(118, 118, 118))))
    .add(ClientTabLayout.createSequentialGroup()
    .add(56, 56, 56)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
    .add(lblClientName)
    .add(txtClientName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
    .add(lblClientSurname)
    .add(txtClientSurname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(btnClientAdd))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
    .add(lblClientType)
    .add(choClientType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .add(21, 21, 21))
    );

    HotelPanes.addTab("tab1", ClientTab);

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.Gro upLayout.LEADING)
    .add(HotelPanes, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.Gro upLayout.LEADING)
    .add(HotelPanes, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
    );

    pack();
    }// </editor-fold>

    private void btnClientAddMouseClicked(java.awt.event.MouseEvent evt) {
    DBRoutines db = new DBRoutines("ftp.mcast.edu.mt", "gerards", "gerards", "***");
    db.connect();
    String clientInsert = "INSERT INTO apfclients (ClientID,Name,Surname,Address,Telephone,Mobile,Ty pe,Treatment) VALUE (?,?,?,?,?,?,?,?)";
    PreparedStatement sqlStatement = null;

    try {
    sqlStatement = db.dbConnection.prepareStatement(clientInsert);
    sqlStatement.setString(1, txtClientId.getText());
    sqlStatement.setString(2, txtClientName.getText());
    sqlStatement.setString(3, txtClientSurname.getText());
    sqlStatement.setString(4, txtClientAddress.getText());
    sqlStatement.setString(5, txtClientTel.getText());
    sqlStatement.setString(6, txtClientMobile.getText());
    sqlStatement.setString(7, choClientType.getSelectedItem());

    if (choClientType.getSelectedItem().equals("VIP")) {
    sqlStatement.setString(8,"Wifi, Sweets, Champagne");
    } else if (choClientType.getSelectedItem().equals("Family")) {
    sqlStatement.setString(8,"Sweets");
    } else if (choClientType.getSelectedItem().equals("Couple")) {
    sqlStatement.setString(8,"Champagne");
    } else if (choClientType.getSelectedItem().equals("Business" )) {
    sqlStatement.setString(8,"Wifi");
    } else {
    sqlStatement.setString(8,"null");
    }
    sqlStatement.executeUpdate();

    JOptionPane.showMessageDialog(null, "Client has been successfully added!");
    } catch (SQLException ex) {
    ex.printStackTrace();
    }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new HotelGUI().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    private javax.swing.JPanel ClientTab;
    private javax.swing.JTabbedPane HotelPanes;
    private javax.swing.JButton btnClientAdd;
    private java.awt.Choice choClientType;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblClientAddress;
    private javax.swing.JLabel lblClientId;
    private javax.swing.JLabel lblClientMobile;
    private javax.swing.JLabel lblClientName;
    private javax.swing.JLabel lblClientSurname;
    private javax.swing.JLabel lblClientTelephone;
    private javax.swing.JLabel lblClientType;
    private javax.swing.JEditorPane txtClientAddress;
    private javax.swing.JTextField txtClientId;
    private javax.swing.JTextField txtClientMobile;
    private javax.swing.JTextField txtClientName;
    private javax.swing.JTextField txtClientSurname;
    private javax.swing.JTextField txtClientTel;
    // End of variables declaration

    }

Similar Threads

  1. help needed!!! :S
    By mark-mlt in forum Networking
    Replies: 1
    Last Post: 04-14-2008, 09:27 AM
  2. Help Needed
    By pks in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 12:07 AM
  3. Uni Project - GUI - Help Needed
    By deeadeed in forum New To Java
    Replies: 0
    Last Post: 12-03-2007, 11:10 PM
  4. help needed.
    By dirtycash in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 09:17 PM
  5. jfreeReport help needed
    By sandor in forum XML
    Replies: 1
    Last Post: 04-20-2007, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •