insert data into database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: insert data into database

  1. #1
    Join Date
    Mar 2005
    Posts
    2

    Exclamation insert data into database

    I am writing a java application that allows users to enter their details in text fields and then store their information into a MS Access database.

    The database is connected and working but I just can't get the data from the textfield into the database when i press the button.

    I am using an INSERT statement but keep getting a message saying "error in INSERT statement".
    eg:-
    query="INSERT INTO Profiles (Gender) VALUES"+text+"";

    ResultSet resultSet = statement.executeQuery(query);

    Any ideas please?

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    If you have an error in the insert (not syntax error) then we need the table
    definition and the contents of the failed insert string to see what is wrong here.
    eschew obfuscation

  3. #3
    Join Date
    Mar 2005
    Posts
    2

    Question

    When i press the button the error i get is: "[Microsoft] [ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement". Here is a sample of the code

    driver="sun.jdbc.odbc.JdbcOdbcDriver";
    url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/My Documents/Members";
    text=genderField.getText();

    try{
    //Load database driver class
    Class.forName(driver);
    //Establish connection to database
    connection = DriverManager.getConnection(url,"","");

    //Create statement for inserting into database
    statement = connection.createStatement();

    //Insert into database
    ResultSet resultSet = statement.executeUpdate("INSERT INTO Profiles (Gender) Values" +text+"");
    }
    Last edited by bob8100; 03-27-2005 at 01:20 PM.

  4. #4
    Join Date
    Mar 2005
    Posts
    3
    ResultSet resultSet = statement.executeUpdate("INSERT INTO Profiles (Gender) Values" +text);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center