title: SQL in Java sending to two Tables but having errors
body: <p><strong>*********************************SOLVED BY I-LOVE-2-REVIVE SEE BELOW******************</strong></p>
  
  <p>data base was throwing back error wen adding a "fileNo" as the other fields that went to default where dates and defualt was set to 0. so in access =Date() was set in default and Error was solved.thanks again all!</p>
  
  <p><strong>*******************************************END OF SOLUTION***************************************</strong></p>
  
  <p>im having some serious trouble and my brain has completely melted on me trying to solve it!</p>
  
  <p>so basically i have 2 tables in my access Database a "Files" Table containing FileNo,TrailDate,Clientname.
  another Called "ToDO" containing 
  FileNo, 1,1a,1b, 2,2a,2b ECT. (1 relates to Thing you need to do and 1a relates to the date it needs to be accomplished)</p>
  
  <p>i then have 2 entry points on my java program.
  one you enter a file. this sends to the file database and works fine!
  the second pulls the "FileNo" column from "Files" to a Jcombo box and once you click that file Number searched the "ToDO" table for its data in 1,1a,2,2a ect. then outputs this so the user can edit or review. </p>
  
  <p>my problem im having now is i need it so that when you input a new file in AddFile GUI to then add that FileNo to the "ToDO" Database as well.</p>
  
  <p>this is a sample of the code im working with</p>
  
  <pre><code>try { //// WORKING  
         PreparedStatement statement = (PreparedStatement)connect.prepareStatement("INSERT INTO Files(FileNo,TrialDate,ClientName)VALUES('"+fileNumber+"','"+trialDate+"','"+clientName+"')");
              statement.executeUpdate();
              statement.close();
              connect.close();
              JOptionPane.showMessageDialog(null, "File added to Database. Returning to main menu");
              System.out.println("Success!");
              adfFrame.setVisible(false);
              mainMenu();
  
          }catch(Exception ex){
              JOptionPane.showMessageDialog(null, "File name already in Database!");
              System.out.println("Error" + ex);}
  </code></pre>
  
  <p>now when i change this code to :</p>
  
  <pre><code>try { 
         PreparedStatement statement = (PreparedStatement)connect.prepareStatement("INSERT INTO ToDO(FileNo)VALUES('"+fileNumber+"')");
                              statement.executeUpdate();
              statement.close();
              connect.close();
              JOptionPane.showMessageDialog(null, "File added to Database. Returning to main menu");
              System.out.println("Success!");
              adfFrame.setVisible(false);
              mainMenu();
  
          }catch(Exception ex){
              JOptionPane.showMessageDialog(null, "File name already in Database!");
              System.out.println("Error" + ex);}
  </code></pre>
  
  <p>i get a SQL exception reading: net.ucanaccess.jdbc.UcanaccessSQLException: incompatible data type in conversion</p>
  
  <p>But the thing is i don't understand how that can be possible!? as in my database design the FileNo in "TodO" Table is LongText as it is in "Files" Table i have no issues with the file input at all but the second i try to add the same data to ToDO i get error!</p>
  
  <p>i am fairly new Java and this is my first full project so apologies if this is trivial but iv searched and searched and i cant find a suitable answer for my problem :(</p>
  
  <p>.......EDIT....</p>
  
  <p>this the all the code for the method.</p>
  
  <pre><code>   private void fileFrame() {    
      //POPULATES CLIENTS STRING ARRAY 
  
      String[] clients= new String[noclients];
      String sql1 = "SELECT ClientName FROM ClientTable";
          try {
              rs = st.executeQuery(sql1);
          } catch (SQLException ex) {
              Logger.getLogger(Login1.class.getName()).log(Level.SEVERE, null, ex);
          }
      System.out.println(sql1);
      int count= 0;           
          try {
              while (rs.next()){
                  clients[count] = rs.getString("ClientName");
                  count = count + 1; 
                  System.out.println("Clients="+clients);
              }   } catch (SQLException ex) {
              Logger.getLogger(Login1.class.getName()).log(Level.SEVERE, null, ex);
          }
  //FINISHES CLIENT ARRAY POPULATION.        
      JLabel l = new JLabel("File Reference");
      JLabel l1 = new JLabel("Trial Date");
      JTextField t = new JTextField(10);
      JTextField t1 = new JTextField(10);
      JComboBox clientList = new JComboBox(clients);
  
      JButton b = new JButton("Save");
      JButton b1 = new JButton("Save and Exit");
  
  
  
          adfFrame.setSize(500,800);
          adfFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          adfFrame.setLocation(700, 500);
          adfFrame.setVisible(true);
          //Adds TExt Fields/Labels/Button to the GUI
          JPanel p = new JPanel();
          p.add(l);
          p.add(t);
          p.add(l1);
          p.add(t1);
          p.add(clientList);
          p.add(b);
          p.add(b1);
  
          adfFrame.add(p);     
          p.getRootPane().setDefaultButton(b);
  
          //save button pressed
          b.addActionListener(new ActionListener() {
  
  
              @Override
          public void actionPerformed(ActionEvent e) {
              String driver = "net.ucanaccess.jdbc.UcanaccessDriver";
              try {
                  Class.forName(driver);
              } catch (ClassNotFoundException ex) {
                  Logger.getLogger(Login1.class.getName()).log(Level.SEVERE, null, ex);
              }
              //##DECLARES FILEPATH##
              String filePath = "C://Users/Chris/java/Tutorials GUI/2.Login page with Database/Login1/Login1.accdb";
  
              //##PULL FILEPATH FROM ABOVE##
              String db = "jdbc:ucanaccess://"+filePath;
              Connection connect = null;
              try {
                  connect = DriverManager.getConnection(db);
                  /// CONNECTION  MADE
              } catch (SQLException ex) {
                  Logger.getLogger(Login1.class.getName()).log(Level.SEVERE, null, ex);
              }
              String fileNumber=t.getText();
              //System.out.println(fileNumber);
              String clientName=clientList.getSelectedItem().toString();
              //System.out.println(clientName);
              String trialDate =t1.getText();
              //System.out.println(trialDate);
  
  
              try { //// WORKING  
             PreparedStatement statement = (PreparedStatement)connect.prepareStatement("INSERT INTO Files(FileNo,TrialDate,ClientName)VALUES('"+fileNumber+"','"+trialDate+"','"+clientName+"')");
            System.out.println("1");
             statement.executeUpdate(); 
             System.out.println(statement);
             statement.close();
                  //statement.setString(1,clientName);
                  //statement.setString(2,yn);
             //PreparedStatement stotement = (PreparedStatement)connect.prepareStatement("INSERT INTO ToDO [FileNo] VALUES('"+fileNumber+"')");
            //System.out.println("2");
            //stotement.executeUpdate(); System.out.println(stotement);
                 // stotement.close();
                  connect.close();
                  System.out.println("Success!");
  
              }catch(Exception ex){
                  JOptionPane.showMessageDialog(null, "File already in Database!");
                  System.out.println("Error" + ex);
              }
  
  
  
              t.setText("");
              t1.setText("");
              fcount();
          }
      });
  
          //Save and exit button pressed
          b1.addActionListener(new ActionListener() {
  
  
              @Override
          public void actionPerformed(ActionEvent e) {
              String driver = "net.ucanaccess.jdbc.UcanaccessDriver";
              try {
                  Class.forName(driver);
              } catch (ClassNotFoundException ex) {
                  Logger.getLogger(Login1.class.getName()).log(Level.SEVERE, null, ex);
              }
              //##DECLARES FILEPATH##
              String filePath = "C://Users/Chris/java/Tutorials GUI/2.Login page with Database/Login1/Login1.accdb";
  
              //##PULL FILEPATH FROM ABOVE##
              String db = "jdbc:ucanaccess://"+filePath;
              Connection connect = null;
              try {
                  connect = DriverManager.getConnection(db);
                  /// CONNECTION  MADE
              } catch (SQLException ex) {
                  Logger.getLogger(Login1.class.getName()).log(Level.SEVERE, null, ex);
              }
              String fileNumber=t.getText();
              //System.out.println(fileNumber);
              String clientName=clientList.getSelectedItem().toString();
              //System.out.println(clientName);
              String trialDate =t1.getText();
              //System.out.println(trialDate);
  
  
              try { //// WORKING  
             PreparedStatement statement = (PreparedStatement)connect.prepareStatement("INSERT INTO Files(FileNo,TrialDate,ClientName)VALUES('"+fileNumber+"','"+trialDate+"','"+clientName+"')");
  
                  statement.executeUpdate();
                  statement.close();
                  connect.close();
                  JOptionPane.showMessageDialog(null, "File added to Database. Returning to main menu");
                  System.out.println("Success!");
  
              }catch(Exception ex){
                  JOptionPane.showMessageDialog(null, "File name already in Database!");
                  System.out.println("Error" + ex);
                  adfFrame.setVisible(false);
                  mainMenu();
  
  
              }
  
  try { 
             PreparedStatement statement = (PreparedStatement)connect.prepareStatement("INSERT INTO ToDO(FileNo)VALUES('"+fileNumber+"')");
                  statement.executeUpdate();
                  statement.close();
                  connect.close();
                  JOptionPane.showMessageDialog(null, "File added to Database. Returning to main menu");
                  System.out.println("Success!");
  
              }catch(Exception ex){
                  JOptionPane.showMessageDialog(null, "File name already in Database!");
                  System.out.println("Error" + ex);
  
           }
  
              t.setText("");
              t1.setText("");
              fcount();
  
          }
      });
  
  }
  </code></pre>
  
  <p>in the above please note i have 2 buttons doing the same thing. B and B1 B1 usually has a GUI Exit on it as a save and exit sort of deal.
   there may be some miner errors in this code please ignore those as i have very quickly edited it befor i ran out the door to work and posted here.</p>
  
  <p>thanks again for looking :)</p>