jdbc to odbc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brendanmcdonagh
    New Member
    • Nov 2007
    • 153

    jdbc to odbc

    Hi all,

    After an hour of searching i have decided to surrender and ask!

    Code:
    s.execute("INSERT INTO customers values(?," +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')")
    is saying [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect

    This is because of the first value ?. I have an auto increment table in microsoft access but if I don't enter ? as the value for the auto increment column i get a mismatch error.

    Any one know the proper syntax for my problem(how to let access add the auto increment data when working via java)?

    Regards

    Brendan
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by brendanmcdonagh
    Hi all,

    After an hour of searching i have decided to surrender and ask!

    Code:
    s.execute("INSERT INTO customers values(?," +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')")
    is saying [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect

    This is because of the first value ?. I have an auto increment table in microsoft access but if I don't enter ? as the value for the auto increment column i get a mismatch error.

    Any one know the proper syntax for my problem(how to let access add the auto increment data when working via java)?

    Regards

    Brendan
    I don't know if it matters much but you're missing a single tick (') before the name field. (it's better to use PreparedStateme nts for this purpose for a couple of reasons).

    kind regards,

    Jos

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by brendanmcdonagh
      This is because of the first value ?. I have an auto increment table in microsoft access but if I don't enter ? as the value for the auto increment column i get a mismatch error.
      Code:
      String query = "insert into TABLE(col1....coln) values(val1....valn)";
      s.execute(query);

      Comment

      • brendanmcdonagh
        New Member
        • Nov 2007
        • 153

        #4
        Code:
        String query = "INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')"; 
        s.execute(query);
        new code - same error message!

        Regards

        Brendan

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by brendanmcdonagh
          Code:
          String query = "INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')"; 
          s.execute(query);
          new code - same error message!

          Regards

          Brendan
          Why are you putting ? mark?
          Are you trying to put the value automatically?
          Did you see my post ... simply mention the column name and put the values accordingly and no need to put the put auto increment value.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by dmjpro
            Why are you putting ? mark?
            ....
            Because that is the correct way of doing it.
            Read the PreparedStateme nt API for details.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by r035198x
              Because that is the correct way of doing it.
              Read the PreparedStateme nt API for details.
              That is not what the OP attempted to use it for; the first column of that table is an auto-increment column and the OP was trying to express ? as 'I don't know what to put here'; Dmjpro is probably right here: explicitly mention all column names for which values are supplied.

              kind regards,

              Jos

              Comment

              • brendanmcdonagh
                New Member
                • Nov 2007
                • 153

                #8
                Code:
                String query = "INSERT INTO customers(id, customerName, customerAddress, customerEmail, customerNumber, customerPurchase/s) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
                This is now showing a sql syntax error when executed??

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by brendanmcdonagh
                  Code:
                  String query = "INSERT INTO customers(id, customerName, customerAddress, customerEmail, customerNumber, customerPurchase/s) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
                  This is now showing a sql syntax error when executed??
                  I can see a /s in that string; better print out that string before you feed it to your sql engine. For your next post: it would be convenient if we know too what the exact error message was.

                  kind regards,

                  Jos

                  Comment

                  • brendanmcdonagh
                    New Member
                    • Nov 2007
                    • 153

                    #10
                    and the answer is......

                    Code:
                    s.execute("INSERT INTO customers(customerName, customerAddress, customerEmail, customerNumber, customerPurchase) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')");
                    p.s any one know how to close a frame rather than just setVisible(fals e)

                    I have frame1 opening frame2(I want to close frame1 here) and then frame2 is opening a new instance of frame1(i want to close frame2 here)

                    Any ideas?

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by brendanmcdonagh
                      and the answer is......

                      Code:
                      s.execute("INSERT INTO customers(customerName, customerAddress, customerEmail, customerNumber, customerPurchase) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')");
                      p.s any one know how to close a frame rather than just setVisible(fals e)

                      I have frame1 opening frame2(I want to close frame1 here) and then frame2 is opening a new instance of frame1(i want to close frame2 here)

                      Any ideas?
                      So it was that misplaced / character? You can get rid of a JFrame by calling the dispose() method inherited from the Window class.

                      kind regards,

                      Jos

                      Comment

                      Working...