Page 1 of 2 12 LastLast
Results 1 to 20 of 24
Like Tree1Likes

Thread: SQL problems

  1. #1
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default SQL problems

    Hi. I have a java class that the user puts in the information and then it sends it to another class to put it into the database. But its not working. It's running but not putting any information in the database. Here's the code from the program that sends the information:
    Java Code:
    private void button1MouseClicked(MouseEvent e) 
          {
             String name1 = textField1.getText();
             String name2 = textField2.getText();
             String playup = textField3.getText();
             String rotate = textField4.getText();
             SQLUserinfo suser = new SQLUserinfo(name1, name2, playup, rotate);
             Scorekeeper scrkper = new Scorekeeper("");
             this.setVisible(false);
          }
    and here's the code from the SQL class that is suppose to insert the information into the database.
    Java Code:
    	private String naam1;
       	private String naam2;
       	private String playup;
       	private String rotate;
       	public SQLUserinfo(String nm1, String nm2, String plyp, String rtte)
       	{
       	naam1 = nm1;
       	naam2 = nm2;
       	playup = plyp;
       	rotate = rtte;
       	}
       	
           SQLUserinfo ()throws SQLException
          {
            updateMthd("INSERT INTO Extra" + "VALUES(naam1, naam2, playup, rotate)");      
          }
    please help me!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: SQL problems

    Your SQLUserinfo class has two constructors, one that appears to try to update the database (method not shown, and it appears to try to do this before any data has been placed into the class fields), and the other that doesn't. Guess which one you're calling?
    Solarsonic likes this.

  3. #3
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    haha lol cool stated here is the updateMthd that I left out erlier:
    Java Code:
    void updateMthd (String update) throws SQLException
          {
             stmt = conn.createStatement();
             stmt.executeUpdate(update);
             stmt.close();
          }
    I did the following with the constructor issue:
    Java Code:
    public class SQLUserinfo
       {
          Connection conn = connect();
          Statement stmt;
       	
          private String naam1;
          private String naam2;
          private String playup;
          private String rotate;
       
           SQLUserinfo (String nm1, String nm2, String plyp, String rtte)throws SQLException
          {
             naam1 = nm1;
             naam2 = nm2;
             playup = plyp;
             rotate = rtte;
             updateMthd("INSERT INTO Extra" + "VALUES(naam1, naam2, playup, rotate)");      
          }
    and took out this because it was giving an error.
    Java Code:
     public static void main (String [] args) throws SQLException
          {
             //new SQLUserinfo ();
          }
    But now it gives me the following error at the Userinfo class:
    Userinfo.java:31: unreported exception java.sql.SQLException; must be caught or declared to be thrown
    SQLUserinfo suser = new SQLUserinfo(name1, name2, playup, rotate);
    ^

    At this code:
    Java Code:
    private void button1MouseClicked(MouseEvent e) 
          {
             String name1 = textField1.getText();
             String name2 = textField2.getText();
             String playup = textField3.getText();
             String rotate = textField4.getText();
             SQLUserinfo suser = new SQLUserinfo(name1, name2, playup, rotate);
             Scorekeeper scrkper = new Scorekeeper("");
             this.setVisible(false);
          }

  4. #4
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    Oh that arrow is suppose to be at new

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: SQL problems

    Your constructor throws an exception and this must be caught and handled. If this makes no sense, please check out the exceptions tutorial at the Oracle Java tutorials.

  6. #6
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    It makes sense..I know a little of error handling and exceptions, but not enough to solve my problem. I have red through some of the tutorials...

  7. #7
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    please help!!

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: SQL problems

    Quote Originally Posted by Johanis View Post
    please help!!
    Please tell us what in the Exceptions tutorials confuses you!

  9. #9
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    I RunTimeException
    Java Code:
     private void button1MouseClicked(MouseEvent e) 
          {
             try
             {
                String name1 = textField1.getText();
                String name2 = textField2.getText();
                String playup = textField3.getText();
                String rotate = textField4.getText();
                SQLUserinfo suser = new SQLUserinfo(name1, name2, playup, rotate);
                Scorekeeper scrkper = new Scorekeeper("");
                this.setVisible(false);
             }
                 catch (SQLException ex)
                {
                   throw new RuntimeException(ex);
                }
          
          }
    but now it gives me the following error to do with the other class.

    Java Code:
    Connected to database
    
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    	at Userinfo.button1MouseClicked(Userinfo.java:40)
    	at Userinfo.access$100(Userinfo.java:12)
    	at Userinfo$2.mouseClicked(Userinfo.java:204)
    	at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
    	at java.awt.Component.processMouseEvent(Component.java:6041)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    	at java.awt.Component.processEvent(Component.java:5803)
    	at java.awt.Container.processEvent(Container.java:2058)
    	at java.awt.Component.dispatchEventImpl(Component.java:4410)
    	at java.awt.Container.dispatchEventImpl(Container.java:2116)
    	at java.awt.Component.dispatchEvent(Component.java:4240)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3995)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    	at java.awt.Container.dispatchEventImpl(Container.java:2102)
    	at java.awt.Window.dispatchEventImpl(Window.java:2429)
    	at java.awt.Component.dispatchEvent(Component.java:4240)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Caused by: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    	at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    	at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    	at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
    	at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
    	at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
    	at SQLUserinfo.updateMthd(SQLUserinfo.java:75)
    	at SQLUserinfo.<init>(SQLUserinfo.java:24)
    	at Userinfo.button1MouseClicked(Userinfo.java:34)
    	... 23 more

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: SQL problems

    In your method that receives the String that makes up your SQL query, print it and see for yourself; the query isn't correct.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    I can't figure out what's wrong. I suspect it might have something to do with the Userinfo class where i put in the RuntimeException. Otherwise it's got something to do with my database. I just really don't know.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: SQL problems

    According to your code:

    Java Code:
       updateMthd("INSERT INTO Extra" + "VALUES(naam1, naam2, playup, rotate)");
    Your database receives the String "INSERT INTO ExtraVALUES(naam1, naam2, playup, rotate)" Note the lack of a space between "Extra" and "VALUES" ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    I have changed that a long time ago and it still doens't work.
    Java Code:
     private String naam1;
          private String naam2;
          private String playup;
          private String rotate;
       
           SQLUserinfo (String nm1, String nm2, String plyp, String rtte)throws SQLException
          {
             naam1 = nm1;
             naam2 = nm2;
             playup = plyp;
             rotate = rtte;
             updateMthd("INSERT INTO Extra VALUES(naam1, naam2, playup, rotate)");
          }

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: SQL problems

    Quote Originally Posted by Johanis View Post
    I have changed that a long time ago and it still doens't work.
    Why didn't you tell us about it? Do you want us guess what is wrong in your secretly changing code? Better guess yourself then because you have more information than we do. b.t.w. naam1, naam2, playup and rotate don't mean anything to your database SQL engine.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: SQL problems

    As josah said, ""INSERT INTO Extra VALUES(naam1, naam2, playup, rotate)" means nothing too the sql engine you're using.
    Try and think about what naam1, naam2, playup and rotate are, and how you're trying to use them. Then, if you get really stuck, come reply on here and I'm sure one of us will be happy too talk you through where you've gone wrong :)

  16. #16
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    Quote Originally Posted by JosAH View Post
    Why didn't you tell us about it? Do you want us guess what is wrong in your secretly changing code? Better guess yourself then because you have more information than we do. b.t.w. naam1, naam2, playup and rotate don't mean anything to your database SQL engine.

    Jos
    It wasn't on purpose. It was whilst I was trying everything, and I forgot the code here wasn't the same as mine. I know you have to sort out a LOT of problems here and you can get fed up easily, but through all the rush of me trying to finish my project in time and trying stuff to try and solve the problem, something like this happens easily... (and it wouldn't be logic to post everything I have tried)
    I don't know what to try anymore.
    Really sorry though
    Johannes

  17. #17
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    Here is both my programs:
    Java Code:
     //Johannes van Zyl
    //Userinfo
    //GUI wat die inligting vanaf die gebruiker kry.
      
       import java.sql.*;
       import java.awt.*;
       import java.awt.event.*;
       import java.beans.*;
       import javax.swing.*;
       import javax.swing.event.*;
    
        public class Userinfo extends JDialog 
       {
         
           public Userinfo()
          {
             initComponents();
             this.setVisible(true);
          }
          
           public static void main(String[]args)
          {
             Userinfo obj = new Userinfo();
          }
          
           private void button1MouseClicked(MouseEvent e) 
          {
             String name1 = textField1.getText();
             String name2 = textField2.getText();
             String playup = textField3.getText();
             String rotate = textField4.getText();
             try
             {
                SQLUserinfo suser = new SQLUserinfo(name1, name2, playup, rotate);
             }
                 catch (SQLException ex)
                {
                   throw new RuntimeException(ex);
                }
             finally
             {
                Scorekeeper scrkper = new Scorekeeper("");
                this.setVisible(false);
             }
             
          }
          
           private void button2MouseClicked(MouseEvent e) 
          {
             Scorekeeper scrkper = new Scorekeeper("");
             this.setVisible(false);
          }
       
           private void radioButton1MouseClicked(MouseEvent e)
          {
          // TODO add your code here
          }
       
           private void radioButton2MouseClicked(MouseEvent e)
          {
           // TODO add your code here
          }
       
           private void menuItem1ActionPerformed(ActionEvent e) 
          {
             int antwoord = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?");
             if (antwoord == JOptionPane.YES_OPTION) 
             {
                System.exit(0);
             } 
          }
            		
           private void initComponents() {
          // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
          // Generated using JFormDesigner non-commercial license
             menuBar1 = new JMenuBar();
             menu1 = new JMenu();
             menuItem1 = new JMenuItem();
             label1 = new JLabel();
             label2 = new JLabel();
             textField1 = new JTextField();
             textField2 = new JTextField();
             label3 = new JLabel();
             label4 = new JLabel();
             textField3 = new JTextField();
             textField4 = new JTextField();
             button1 = new JButton();
             label5 = new JLabel();
             textField5 = new JTextField();
             textField6 = new JTextField();
             textField7 = new JTextField();
             separator1 = new JSeparator();
             label6 = new JLabel();
             label7 = new JLabel();
             label8 = new JLabel();
             label9 = new JLabel();
             label10 = new JLabel();
             label12 = new JLabel();
             label13 = new JLabel();
             textField8 = new JTextField();
             textField9 = new JTextField();
             textField10 = new JTextField();
             textField12 = new JTextField();
             textField13 = new JTextField();
             textField14 = new JTextField();
             scrollPane1 = new JScrollPane();
             textPane1 = new JTextPane();
             button2 = new JButton();
             label11 = new JLabel();
             radioButton1 = new JRadioButton();
             radioButton2 = new JRadioButton();
             separator2 = new JSeparator();
          
          //======== this ========
             setTitle("Table Tennis Score Keeper");
             Container contentPane = getContentPane();
             contentPane.setLayout(null);
          
          //======== menuBar1 ========
             {
             
             //======== menu1 ========
                {
                   menu1.setText("Options");
                
                //---- menuItem1 ----
                   menuItem1.setText("Exit");
                   menuItem1.addActionListener(
                          new ActionListener() {
                             @Override
                             public void actionPerformed(ActionEvent e) {
                               menuItem1ActionPerformed(e);
                            }
                         });
                   menu1.add(menuItem1);
                }
                menuBar1.add(menu1);
             }
             setJMenuBar(menuBar1);
          
          //---- label1 ----
             label1.setText("Player 1 name");
             label1.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label1);
             label1.setBounds(75, 90, 86, 15);
          
          //---- label2 ----
             label2.setText("Player 2 name");
             label2.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label2);
             label2.setBounds(75, 140, 95, 15);
          
          //---- textField1 ----
             textField1.setBackground(Color.red);
             textField1.setForeground(Color.white);
             textField1.setFont(new Font("Tahoma", Font.BOLD, 16));
             textField1.setText("Ping");
             textField1.setToolTipText("player 1 name");
             contentPane.add(textField1);
             textField1.setBounds(40, 110, 155, 26);
          
          //---- textField2 ----
             textField2.setBackground(Color.blue);
             textField2.setForeground(Color.white);
             textField2.setFont(new Font("Tahoma", Font.BOLD, 16));
             textField2.setText("Pong");
             textField2.setToolTipText("Player 2 name");
             contentPane.add(textField2);
             textField2.setBounds(40, 160, 155, 26);
          
          //---- label3 ----
             label3.setText("Play up to");
             label3.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label3);
             label3.setBounds(245, 90, 70, 15);
          
          //---- label4 ----
             label4.setText("Rotates serves every");
             label4.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label4);
             label4.setBounds(210, 140, 140, 15);
          
          //---- textField3 ----
             textField3.setFont(new Font("Tahoma", Font.PLAIN, 16));
             textField3.setText("21");
             textField3.setHorizontalAlignment(SwingConstants.CENTER);
             textField3.setToolTipText("Match total");
             contentPane.add(textField3);
             textField3.setBounds(255, 110, 45, 26);
          
          //---- textField4 ----
             textField4.setFont(new Font("Tahoma", Font.PLAIN, 16));
             textField4.setText("2");
             textField4.setHorizontalAlignment(SwingConstants.CENTER);
             textField4.setToolTipText("serve rotations");
             contentPane.add(textField4);
             textField4.setBounds(255, 160, 45, 26);
          
          //---- button1 ----
             button1.setText("Start");
             button1.setFont(new Font("Tahoma", Font.BOLD, 16));
             button1.setToolTipText("Starts program");
             button1.addMouseListener(
                    new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent e) {
                         button1MouseClicked(e);
                      }
                   });
             contentPane.add(button1);
             button1.setBounds(160, 200, 80, 29);
          
          //---- label5 ----
             label5.setText("Date:");
             label5.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label5);
             label5.setBounds(40, 65, 45, 15);
          
          //---- textField5 ----
             textField5.setFont(new Font("Tahoma", Font.PLAIN, 16));
             textField5.setText("YYYY");
             textField5.setHorizontalAlignment(SwingConstants.LEFT);
             textField5.setToolTipText("Year");
             contentPane.add(textField5);
             textField5.setBounds(75, 60, 50, 26);
          
          //---- textField6 ----
             textField6.setFont(new Font("Tahoma", Font.PLAIN, 16));
             textField6.setText("MM");
             textField6.setHorizontalAlignment(SwingConstants.LEFT);
             textField6.setToolTipText("Month");
             contentPane.add(textField6);
             textField6.setBounds(125, 60, 30, 26);
          
          //---- textField7 ----
             textField7.setFont(new Font("Tahoma", Font.PLAIN, 16));
             textField7.setText("DD");
             textField7.setHorizontalAlignment(SwingConstants.LEFT);
             textField7.setToolTipText("Day");
             contentPane.add(textField7);
             textField7.setBounds(155, 60, 30, 26);
             contentPane.add(separator1);
             separator1.setBounds(0, 235, 415, 5);
          
          //---- label6 ----
             label6.setText("Extra player information (not compulsory):");
             label6.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label6);
             label6.setBounds(55, 240, 275, 15);
          
          //---- label7 ----
             label7.setText("Date of birth:");
             label7.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label7);
             label7.setBounds(15, 260, 90, 15);
          
          //---- label8 ----
             label8.setText("Gender:");
             label8.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label8);
             label8.setBounds(15, 280, 55, 15);
          
          //---- label9 ----
             label9.setText("Place of birth:");
             label9.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label9);
             label9.setBounds(15, 305, 95, 15);
          
          //---- label10 ----
             label10.setText("Member of:");
             label10.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label10);
             label10.setBounds(15, 325, 75, 15);
          
          //---- label12 ----
             label12.setText("Current rank:");
             label12.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label12);
             label12.setBounds(15, 345, 85, 15);
          
          //---- label13 ----
             label13.setText("Motto:");
             label13.setFont(new Font("Tahoma", Font.BOLD, 12));
             contentPane.add(label13);
             label13.setBounds(15, 360, 45, 15);
          
          //---- textField8 ----
             textField8.setText("YYYY");
             textField8.setHorizontalAlignment(SwingConstants.CENTER);
             textField8.setToolTipText("Year");
             contentPane.add(textField8);
             textField8.setBounds(115, 260, 35, 20);
          
          //---- textField9 ----
             textField9.setText("MM");
             textField9.setHorizontalAlignment(SwingConstants.CENTER);
             textField9.setToolTipText("Month");
             contentPane.add(textField9);
             textField9.setBounds(150, 260, 25, 20);
          
          //---- textField10 ----
             textField10.setText("DD");
             textField10.setHorizontalAlignment(SwingConstants.CENTER);
             textField10.setToolTipText("Day");
             contentPane.add(textField10);
             textField10.setBounds(175, 260, 25, 20);
             contentPane.add(textField12);
             textField12.setBounds(115, 305, 240, 20);
             contentPane.add(textField13);
             textField13.setBounds(115, 325, 240, 20);
             contentPane.add(textField14);
             textField14.setBounds(115, 345, 240, 20);
          
          //======== scrollPane1 ========
             {
                scrollPane1.setViewportView(textPane1);
             }
             contentPane.add(scrollPane1);
             scrollPane1.setBounds(115, 365, 240, 55);
          
          //---- button2 ----
             button2.setText("Save information and start");
             button2.setFont(new Font("Tahoma", Font.BOLD, 16));
             button2.setToolTipText("Saves information and starts program");
             button2.addMouseListener(
                    new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent e) {
                         button2MouseClicked(e);
                      }
                   });
             contentPane.add(button2);
             button2.setBounds(70, 430, 270, 29);
          
          //---- label11 ----
             label11.setText("Table Tennis Score Keeper");
             label11.setFont(new Font("Tahoma", Font.BOLD, 30));
             label11.setForeground(new Color(0, 102, 0));
             contentPane.add(label11);
             label11.setBounds(5, 0, 405, 37);
          
          //---- radioButton1 ----
             radioButton1.setText("Male");
             radioButton1.addMouseListener(
                    new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent e) {
                         radioButton1MouseClicked(e);
                      }
                   });
             contentPane.add(radioButton1);
             radioButton1.setBounds(115, 280, 70, 23);
          
          //---- radioButton2 ----
             radioButton2.setText("Female");
             radioButton2.addMouseListener(
                    new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent e) {
                         radioButton2MouseClicked(e);
                      }
                   });
             contentPane.add(radioButton2);
             radioButton2.setBounds(185, 280, 85, 23);
             contentPane.add(separator2);
             separator2.setBounds(0, 475, 415, 5);
          
             { // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < contentPane.getComponentCount(); i++) {
                   Rectangle bounds = contentPane.getComponent(i).getBounds();
                   preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                   preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = contentPane.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                contentPane.setMinimumSize(preferredSize);
                contentPane.setPreferredSize(preferredSize);
             }
             pack();
             setLocationRelativeTo(getOwner());
          // JFormDesigner - End of component initialization  //GEN-END:initComponents
          }
       
       // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
       // Generated using JFormDesigner non-commercial license
          private JMenuBar menuBar1;
          private JMenu menu1;
          private JMenuItem menuItem1;
          private JLabel label1;
          private JLabel label2;
          private JTextField textField1;
          private JTextField textField2;
          private JLabel label3;
          private JLabel label4;
          private JTextField textField3;
          private JTextField textField4;
          private JButton button1;
          private JLabel label5;
          private JTextField textField5;
          private JTextField textField6;
          private JTextField textField7;
          private JSeparator separator1;
          private JLabel label6;
          private JLabel label7;
          private JLabel label8;
          private JLabel label9;
          private JLabel label10;
          private JLabel label12;
          private JLabel label13;
          private JTextField textField8;
          private JTextField textField9;
          private JTextField textField10;
          private JTextField textField12;
          private JTextField textField13;
          private JTextField textField14;
          private JScrollPane scrollPane1;
          private JTextPane textPane1;
          private JButton button2;
          private JLabel label11;
          private JRadioButton radioButton1;
          private JRadioButton radioButton2;
          private JSeparator separator2;
       // JFormDesigner - End of variables declaration  //GEN-END:variables
       }
    Java Code:
    //Johannes van Zyl
    //java class for Userinfo and Scorekeeper and SQL for SQLUserinfo.mdb
    	
       import java.sql.*;
       import java.io.*;
       import javax.swing.*;
       
        public class SQLUserinfo
       {
          Connection conn = connect();
          Statement stmt;
       	
          private String naam1;
          private String naam2;
          private String playup;
          private String rotate;
       
           SQLUserinfo (String nm1, String nm2, String plyp, String rtte)throws SQLException
          {
             updateMthd("INSERT INTO Extra VALUES('naam1', 'naam2', 'playup', 'rotate')");
             displayMthd("", "SELECT * FROM Extra");
          }
          
       	//Make a connection
           public Connection connect ()
          {
          
             //Load driver
             try
             {
                Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
             }
                 catch (ClassNotFoundException e)
                {
                   System.out.println ("Cannot load driver");
                }
          
             //Add name of database
             try
             {
                String dbName = "SQLUserinfo.mdb";
                conn = DriverManager.getConnection ("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + dbName);
                System.out.println ("Connected to database\n");
             }
                 catch (Exception e)
                {
                   System.out.println ("Unable to connect to database");
                }
             return conn;
          }
                  
       	//Create resultset and display information
           void displayMthd (String heading, String sqlStmt) throws SQLException
          {
             stmt = conn.createStatement();		//Standard method from Statement class
             ResultSet rs = stmt.executeQuery(sqlStmt);   //Method from Resultset class (also update query)
               
             System.out.println();
             while (rs.next())
             {
             String p1 = rs.getString("Player1");
             String p2 = rs.getString("Player2");
             String put = rs.getString("Play up to");
             String rot = rs.getString("Rotate");
             }
          	
             System.out.println();   
             stmt.close();
          }
          
           	//Update data in table
           void updateMthd (String update) throws SQLException
          {
             stmt = conn.createStatement();
             stmt.executeUpdate(update);
             stmt.close();
          }
          
          	//Method to create spaces for formatting display
           private String spaces (String s, int width)
          {
             String temp = "";
             for (int I = 0; I<= width - s.length(); I++)
             {
                temp = temp + " ";
             }
             return temp;
          }
             
          //Main method     
           public static void main (String [] args) throws SQLException
          {
             //new SQLUserinfo ();
          }
          
       }
    Hope it's enough information...

  18. #18
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: SQL problems

    What is the error now that was thrown?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  19. #19
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: SQL problems

    You're missing a painfully obvious issue here bud.

    Java Code:
    updateMthd("INSERT INTO Extra VALUES('naam1', 'naam2', 'playup', 'rotate')");
    You need to debug your program, and look at the actual SQL statement being sent too the engine. Hopefully that'll clear it up for you.

  20. #20
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL problems

    When i run the Userinfo class and click on the start button it gives the following errors:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4.
    	at Userinfo.button1MouseClicked(Userinfo.java:38)
    	at Userinfo.access$100(Userinfo.java:12)
    	at Userinfo$2.mouseClicked(Userinfo.java:207)
    	at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
    	at java.awt.Component.processMouseEvent(Component.java:6041)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    	at java.awt.Component.processEvent(Component.java:5803)
    	at java.awt.Container.processEvent(Container.java:2058)
    	at java.awt.Component.dispatchEventImpl(Component.java:4410)
    	at java.awt.Container.dispatchEventImpl(Container.java:2116)
    	at java.awt.Component.dispatchEvent(Component.java:4240)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3995)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    	at java.awt.Container.dispatchEventImpl(Container.java:2102)
    	at java.awt.Window.dispatchEventImpl(Window.java:2429)
    	at java.awt.Component.dispatchEvent(Component.java:4240)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Caused by: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4.
    	at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    	at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    	at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
    	at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
    	at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
    	at SQLUserinfo.updateMthd(SQLUserinfo.java:80)
    	at SQLUserinfo.<init>(SQLUserinfo.java:25)
    	at Userinfo.button1MouseClicked(Userinfo.java:34)
    	... 23 more
    
     ----jGRASP: operation complete.

Page 1 of 2 12 LastLast

Similar Threads

  1. need help with several problems
    By tidus1103 in forum New To Java
    Replies: 4
    Last Post: 03-11-2011, 01:10 AM
  2. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  3. Problems here
    By Keno777 in forum New To Java
    Replies: 2
    Last Post: 11-13-2009, 11:35 AM
  4. JAR problems
    By Evil Smurf in forum New To Java
    Replies: 4
    Last Post: 09-01-2009, 01:17 AM
  5. many to many problems
    By cecily in forum JDBC
    Replies: 1
    Last Post: 08-02-2007, 05:51 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
  •