Results 1 to 9 of 9

Thread: inserting data into Microsoft database

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    inserting data into Microsoft database

    Hi everyone
    Can anyone please help me to find methods, to use when clicking an button inserting data into table. Example say ageButton by clicking on it insert data into table which already exists in the database. I did use this method but does not work. Thanks a lot
    Code:
     public void orderProduct()
        {
                   String sqlSelect = "INSERT INTO age" +  "valuse (34,dave,short)"; 
           System.out.println(sqlSelect);
           
                    
        }

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: inserting data into Microsoft database

    And the Microsoft database would be... Microsoft Access or MS-SQL Server exactly!
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    Re: inserting data into Microsoft database

    thank you for reply, it is Microsoft Access, and i got all column the same with the SQL statements

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: inserting data into Microsoft database

    This code should be a good example
    Code:
    Connection con = DriverManager.getConnection( database ,"","");
    Statement stmt;
    stmt = con.createStatement();
    String stat = ("SELECT * FROM TEMP"+" WHERE TEST_NAME = "+testName);
    ResultSet rs = stmt.executeQuery(stat);
    rs.next();
    String a = rs.getString("TEST_NAME");
    stmt.close();
    con.close();
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: inserting data into Microsoft database

    Missing space after AGE

    Did not spell VALUES correctly.

    Need single-quotes around string values in the insert list.

    Making sure that you build proper SQL syntax statements helps.

    You have the WRITELINE - you are looking at the SQL statement - correct?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    Re: inserting data into Microsoft database

    Hi thank you for yor help,I try this code but it show that the SQL error. Could you please tell me whatis wrong

    Code:
    
              /** create the SQL insert statement using attribute values */
            connection= DriverManager.getConnection( url ,"","");
            Statement stmt;
            statement = connection.createStatement();
            String stat = ("INSERT INTO product product_anme,price ,size" + " VALUES +  ('Omar','9.90','medium')");
            ResultSet rs = statement.executeQuery(stat);
            rs.next();
            String a = rs.getString(" PRODUCT_NAME ");
            statement.close();
            connection.close();
                
            } catch (Exception e) 
            {
                System.out.println("SQL Error.");
                System.out.println();
            }
        }

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: inserting data into Microsoft database

    That is not the syntax for INSERT.

    Have you ever done an INSERT that worked before?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    Re: inserting data into Microsoft database

    yes,this statement
    Code:
     String sqlInsert = "INSERT INTO customer " + "(door_number,street_name,post_code,phone_number)" + 
                    "VALUES ('" + door_number + "' , '"  + street_name + "' , '" + post_code + "' , '" +
                    phone_number  + "')";

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: inserting data into Microsoft database

    That's great...

    So you realize now that

    INSERT INTO product product_anme,price ,size values...

    is missing ()'s around the field-list

    INSERT INTO product (product_anme,price ,size) values...

    The syntax is - to summarize

    INSERT INTO {tablename} ({field1},{field2}...) values ({value1},{value2}...)

    Simple things like spaces and parenthesis are important to the query parser.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width