Please assist with two questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • donovans
    New Member
    • Oct 2007
    • 21

    Please assist with two questions

    Hey there,

    First question:
    I really need help with debugging this code. I keep getting the java.sql.SQLExc eption: General error, and am now lost at a solution to it...I get this with about 4 of my classes and the other 5 classes work fine. Any ideas?

    Code:
     
    [B]Money.java[/B]
    
    package surveying_reports;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*; 
    import java.util.*;
    import java.text.*;
    
    public class Money extends JFrame
    {    
        JLabel detailsLbl, bankingLbl, oftenLbl, whomLbl, maxLbl;
        JComboBox detailsCB, oftenCB, whomCB, maxCB;
        String[] details = {"Please select...", "SABS Cat 1", "SABS Cat 2", "SABS Cat 2 HD D3", "SABS Cat 2 ADM", "SABS Cat 2 ADM D3", "SABS Cat 3", "SABS Cat 4"};
        String[] often = {"Please select...", "Monthly", "Weekly", "Daily"};
        String[] whom = {"Please select...", "Professional Carriers", "Management", "Other"};
        String[] max = {"Please select...", "> R 5,000.00", "R 5,000.00 - R 12,500.00", "R 12,500.00 - R 25,000.00", "R25,000.00 - R 50,000.00", "R 50,000.00 - R 75,000.00", "R 75,000.00 - R 100,000.00", "R 100,000.00 - R 200,000.00"};
        String detailsS, oftenS, whomS, maxS;
        closeMButtonHandler closeMHandler;
        JButton mButton;
        
        public Money() 
        {
            setTitle("Money");
            
            // Add Labels
            detailsLbl = new JLabel("Details of Safe: ");
            detailsLbl.setSize(200,50);
            detailsLbl.setLocation(10,10);
            bankingLbl = new JLabel("Details of Banking: ");
            bankingLbl.setLocation(10,40);
            bankingLbl.setSize(200,50);
            oftenLbl = new JLabel("How Often: ");
            oftenLbl.setSize(200,50);
            oftenLbl.setLocation(30,68);
            whomLbl = new JLabel("By Whom: ");
            whomLbl.setSize(200,40);
            whomLbl.setLocation(30,100);
            maxLbl = new JLabel("Maximum amount of cash kept on site: ");
            maxLbl.setSize(200,40);
            maxLbl.setLocation(10,130);
            
            // Add ComboBoxes
            detailsCB = new JComboBox(details);
            detailsCB.setSize(200,20);
            detailsCB.setLocation(175,25);
            detailsCB.setMaximumRowCount(4);
            oftenCB = new JComboBox(often);
            oftenCB.setSize(200,20);
            oftenCB.setLocation(175,85);
            oftenCB.setMaximumRowCount(4);
            whomCB = new JComboBox(whom);
            whomCB.setSize(200,20);
            whomCB.setLocation(175,110);
            whomCB.setMaximumRowCount(4);
            maxCB = new JComboBox(max);
            maxCB.setSize(200,20);
            maxCB.setLocation(175,140);
            maxCB.setMaximumRowCount(4);
            
            // Save and Close Button
            mButton =  new JButton("Save and Close");
            mButton.setSize(200,25);
            mButton.setLocation(201,190);
            closeMHandler = new closeMButtonHandler();
            mButton.addActionListener(closeMHandler);
            
            Container mPane = getContentPane();
            mPane.setLayout(null);
            
            mPane.add(detailsLbl);
            mPane.add(bankingLbl);
            mPane.add(oftenLbl);
            mPane.add(whomLbl);
            mPane.add(maxLbl);
            mPane.add(detailsCB);
            mPane.add(oftenCB);
            mPane.add(whomCB);
            mPane.add(maxCB);
            mPane.add(mButton);
            
            setContentPane(mPane); 
            setSize(410,250);
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        }
        
        // Add Save and Close Button and allows functionality
        private class closeMButtonHandler implements ActionListener
        {
            public void actionPerformed(ActionEvent ae)
            {
                try
                {
                     clsSql sqlC = new clsSql();           
                                     
                        String strUpdateMoney = "INSERT INTO tblMoney(SafeDetails,Often,Depositer,MaxAmount)" +
                                       " Values('" + detailsCB.getSelectedItem().toString() + "','" + oftenCB.getSelectedItem().toString() + "','" + whomCB.getSelectedItem().toString() + "','" + maxCB.getSelectedItem().toString() + "')";
                        sqlC.execQuery(strUpdateMoney);
                              }
                catch(Exception e){ 
                     e.printStackTrace();
                }
                setVisible(false);
            }
        }
        
    }
    
    [B]Calling Class: clsSql.java[/B]
    package surveying_reports;
    
    import java.sql.*;
            
    public class clsSql {
        
       Connection connection;
       Statement statement;
       
        /** Creates a new instance of clsSql */
        public clsSql() throws ClassNotFoundException
        {
            loadDriver();
        }
        
        // Load the Driver
    
        public void loadDriver() throws ClassNotFoundException{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        
        // Make the Connection
        public void makeConnection() throws SQLException {
            connection=DriverManager.getConnection("jdbc:odbc:tester");
        }
        
         public void buildStatement() throws SQLException {
           statement = connection.createStatement();
        }
    
        public ResultSet getQuery(String strA) throws SQLException {
          makeConnection();
          buildStatement();
                    
            ResultSet set = null;
            boolean foundResults =
                 statement.execute(strA);
            if (foundResults = true)
            {
                 set = statement.getResultSet();
              
            }
                   
            return set;  
       }
        public void execQuery(String sqlStatement) throws SQLException, ClassNotFoundException{ 
            
          int i;
          
         Connection Updateconnection;
         Statement  Updatestatement;
          
          Updateconnection=DriverManager.getConnection("jdbc:odbc:tester"); 
          Updatestatement = Updateconnection.createStatement();
     
          i =  Updatestatement.executeUpdate(sqlStatement);
          
          Updateconnection.close();
          
        }
        
        public void closeConnection() throws SQLException {
            connection.close();
        }
        
        
    }
    Question 2:
    Now I also want to find out, is there a way to extract information from Microsoft Access 2003 and insert it into a specific location in a Microsoft Word 2003 document?

    Please assist,
    Thanks and Regards,
    Donovan
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    I've copied Question # 2 of this post to the Access Forum.

    Linq ;0)>

    Comment

    • donovans
      New Member
      • Oct 2007
      • 21

      #3
      Thanks very much, I am very appreciative with the help thus far.

      Kind Regards,
      Donovan

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by donovans
        Hey there,

        First question:
        I really need help with debugging this code. I keep getting the java.sql.SQLExc eption: General error, and am now lost at a solution to it...I get this with about 4 of my classes and the other 5 classes work fine. Any ideas?
        Can you give a bit more detailed information please? line number, error message,
        stack trace etc. The JVM showed it all to you; please copy it here.

        kind regards,

        Jos

        Comment

        • donovans
          New Member
          • Oct 2007
          • 21

          #5
          Hey there,

          Thanks for the quick response. This is the error I get for the Money.java file/class. I have the same error for a few others. Basically what has to happen when the money button(ie. money class) is clicked in the run stage, a GUI should pop up, which it does, with different combo boxes to allow selection. Once the selection has been provided, it should save to an access database...it was working, now it gives me this error...I never edited anything on this one....really strange! The error follows.

          init:
          deps-jar:
          Copying 1 file to C:\Documents and Settings\donova ns\My Documents\Studi es\Projects\Sur veying_Reports\ build\classes
          compile:
          run:
          java.sql.SQLExc eption: General error
          at sun.jdbc.odbc.J dbcOdbc.createS QLException(Jdb cOdbc.java:6986 )
          at sun.jdbc.odbc.J dbcOdbc.standar dError(JdbcOdbc .java:7114)
          at sun.jdbc.odbc.J dbcOdbc.SQLExec Direct(JdbcOdbc .java:3110)
          at sun.jdbc.odbc.J dbcOdbcStatemen t.execute(JdbcO dbcStatement.ja va:338)
          at sun.jdbc.odbc.J dbcOdbcStatemen t.executeUpdate (JdbcOdbcStatem ent.java:288)
          at surveying_repor ts.clsSql.execQ uery(clsSql.jav a:56)
          at surveying_repor ts.Money$closeM ButtonHandler.a ctionPerformed( Money.java:104)
          at javax.swing.Abs tractButton.fir eActionPerforme d(AbstractButto n.java:1995)
          at javax.swing.Abs tractButton$Han dler.actionPerf ormed(AbstractB utton.java:2318 )
          at javax.swing.Def aultButtonModel .fireActionPerf ormed(DefaultBu ttonModel.java: 387)
          at javax.swing.Def aultButtonModel .setPressed(Def aultButtonModel .java:242)
          at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Bas icButtonListene r.java:236)
          at java.awt.Compon ent.processMous eEvent(Componen t.java:6038)
          at javax.swing.JCo mponent.process MouseEvent(JCom ponent.java:326 5)
          at java.awt.Compon ent.processEven t(Component.jav a:5803)
          at java.awt.Contai ner.processEven t(Container.jav a:2058)
          at java.awt.Compon ent.dispatchEve ntImpl(Componen t.java:4410)
          at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2116)
          at java.awt.Compon ent.dispatchEve nt(Component.ja va:4240)
          at java.awt.Lightw eightDispatcher .retargetMouseE vent(Container. java:4322)
          at java.awt.Lightw eightDispatcher .processMouseEv ent(Container.j ava:3986)
          at java.awt.Lightw eightDispatcher .dispatchEvent( Container.java: 3916)
          at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2102)
          at java.awt.Window .dispatchEventI mpl(Window.java :2429)
          at java.awt.Compon ent.dispatchEve nt(Component.ja va:4240)
          at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java:599)
          at java.awt.EventD ispatchThread.p umpOneEventForF ilters(EventDis patchThread.jav a:273)
          at java.awt.EventD ispatchThread.p umpEventsForFil ter(EventDispat chThread.java:1 83)
          at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(EventDis patchThread.jav a:173)
          at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:168)
          at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:160)
          at java.awt.EventD ispatchThread.r un(EventDispatc hThread.java:12 1)
          BUILD SUCCESSFUL (total time: 10 seconds)

          Comment

          • donovans
            New Member
            • Oct 2007
            • 21

            #6
            UPDATE: I found the problem to be certain keywords in the Database. All I did was to rename the keywords ie. General to hkGeneral. Just wanted to close this post properly.

            Regards,
            Donovan
            PS: Thanks for all the help.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by donovans
              UPDATE: I found the problem to be certain keywords in the Database. All I did was to rename the keywords ie. General to hkGeneral. Just wanted to close this post properly.

              Regards,
              Donovan
              PS: Thanks for all the help.
              That is good to hear.
              Thanks for posting back and good luck with the rest of it.

              Comment

              • heat84
                New Member
                • Nov 2007
                • 118

                #8
                You read database and write it to the word document using HSWF , its an apache solution for writing to excel and word. Please visit the apache website and read more about POI package.

                Comment

                • donovans
                  New Member
                  • Oct 2007
                  • 21

                  #9
                  Thanks for the help, I have managed to finished my project to present on Monday. I managed to do a huge MailMerge between Access and Word and it seems to have been successful.

                  Once again thanks for all the help.

                  Now I have another question though...I need to create a kind of executable, so that when I put the program on another machine, which doesn't have netbeans, they can run it....any ideas?

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by donovans
                    Thanks for the help, I have managed to finished my project to present on Monday. I managed to do a huge MailMerge between Access and Word and it seems to have been successful.

                    Once again thanks for all the help.

                    Now I have another question though...I need to create a kind of executable, so that when I put the program on another machine, which doesn't have netbeans, they can run it....any ideas?
                    We don't create .exes in Java. We create jar files instead. .exes are platform dependent and that defeats the purpose of using Java which is platform independent.
                    Just have a look at Sun's Jar tool tutorial and you'll find everything you need.

                    Comment

                    • donovans
                      New Member
                      • Oct 2007
                      • 21

                      #11
                      As I said previously....L ife Saver. Thanks very much...will have a look there and let you know.

                      Comment

                      • donovans
                        New Member
                        • Oct 2007
                        • 21

                        #12
                        Hello again,

                        I have looked there and I am still a little unsure of how to create the JAR, so that when I run the program I have created on another machine it will run on that machine without the need to have an SDK installed....

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by donovans
                          Hello again,

                          I have looked there and I am still a little unsure of how to create the JAR, so that when I run the program I have created on another machine it will run on that machine without the need to have an SDK installed....
                          Did you read about it here?

                          Comment

                          • donovans
                            New Member
                            • Oct 2007
                            • 21

                            #14
                            I did but it didn't make any sense, however......

                            You know what? I feel like a numbskull now...hehehe. I only grasped the concept now. The JAR file is a working file that can be transported to any PC with Java SDK installed on it, and it will run....duh....b londe moment :)

                            Thanks very much for the help and giving me the inspiration...

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by donovans
                              I did but it didn't make any sense, however......

                              You know what? I feel like a numbskull now...hehehe. I only grasped the concept now. The JAR file is a working file that can be transported to any PC with Java SDK installed on it, and it will run....duh....b londe moment :)

                              Thanks very much for the help and giving me the inspiration...
                              You don't need the SDK installed, you just need the JRE installed on that PC.

                              Comment

                              Working...