Problem inserting into access database.

I am using the following code to create a table and insert values into an access database. Problem is that it only inserts the first 3 values no matter what order they are in. Any help is appreciated, and thanks in advance.
      stmt.executeUpdate("CREATE TABLE HardDrive (HardDriveID VARCHAR(10),"           + " HardDriveName VARCHAR(30), HardDriveSize VARCHAR(6), Price CURRENCY)");       stmt.executeUpdate("INSERT INTO HardDrive VALUES ('WD3000HLFS','Western Digital VelociRaptor','300 GB',229.99)");       stmt.executeUpdate("INSERT INTO HardDrive VALUES ('ST31000528AS','Seagate Barracuda','1 TB',99.99)");       stmt.executeUpdate("INSERT INTO HardDrive VALUES ('ST3250310AS','Seagate Barracuda','250 GB',47.99)");       stmt.executeUpdate("INSERT INTO HardDrive VALUES ('WD10EADS','Western Digital Caviar Green','1 TB',89.99)");

What did I tell you about not using Access?
This is exactly why. This is an Access related issue, and one that has been discussed many times previously on this site.
Choose. Another. Database.

Similar Messages

  • Unable to update or insert into Access database table using OleDB, and it doesn't return any errors.

    I'm new to VS. I have run the following code. It does not produce any error, and it does not add or update data to my Access database table.
    dbUpdate("UPDATE prgSettings SET varValue='test' WHERE varSetting='test'")   
    Function dbUpdate(ByVal _SQLupdate As String) As String
            Dim OleConn As New OleDbConnection(My.Settings.DatabaseConnectionString.ToString)
            Dim oleComm As OleDbCommand
            Dim returnValue As Object
            Dim sqlstring As String = _SQLupdate.ToString
            Try
                OleConn.Open()
                MsgBox(OleConn.State.ToString)
                oleComm = New OleDbCommand(sqlstring, OleConn)
                returnValue = oleComm.ExecuteNonQuery()
            Catch ex As Exception
                ' Error occurred while trying to execute reader
                ' send error message to console (change below line to customize error handling)
                Console.WriteLine(ex.Message)
                Return 0
            End Try
            MsgBox(returnValue)
            Return returnValue
    End Function
    Any suggestions will be appreciated.
    Thanks.

    You code looks pretty good, at a quick glance.  Maybe you can simplify things a bit.
    For Insert, please see these samples.
    http://www.java2s.com/Code/CSharp/Database-ADO.net/Insert.htm
    For Update, please see these samples.
    http://www.java2s.com/Code/CSharp/Database-ADO.net/Update.htm
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.
    Best to keep samples here to VB.NET
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Reading content to insert into a database for file content searches

    I have a new challenge that has been brought to me.
    There is and existing application that has files being inserted into the database and the customer is having great difficulty in being able to have a search capability against those files. I was thinking that I could do a secondary lookup before the file is actually uploaded and there would be use of the cffile to read the file then insert that data from the read and insert that data into a column of that database the equiled that record. The most important part of this is that the file's content is read from cffile and inserted into a column that actually get's that data into the RBDMS system that will allow for a full text search that would point to that system.
    Any other ideas of how to insert document content into a data record other than using the cffile tag would be most appreciated.
    Thanks in advance.
    Gene

    Most, if not all, database management systems have their own features to read text data from files.  You may prefer that functionality over piping the data through ColdFusion and the database drivers.
    <cffile...> can "read" .doc and .pdf file as in it can read the file from the file system as the binary data they are, but that does not extract the text from the content.  You can do some stuff with CFML to read the text in a pdf file with the <cfpdf...> and related tags and functions.  I'm not aware of similar CFML features that work with doc files, but I know of Java tools that do such as POI.  These are usually fairly straight forward to tap into with ColdFusion.

  • Get the data  from excel and insert into the database

    I want to read the data from excel file, get the data from excel and insert into the database.

    You can use the Apache POI HSSF API to read data from Excel files and you can use the Sun JDBC API to insert data in database.
    This has nothing to do with JSP/JSTL.

  • Insert into SQL database

    Hi,
    I am using xMII v 11.5..I need to insert into SQL database.
    In BLS
    Step 1:I am using an SQL Query1 it fetches data
    Step 2:  I am using 4 calculation Action block to calculate the values
    Step 3: I am inserting the Calculated values using an SQL Query2
    In the links when i evaluate its showing the value but when i check in the SQL Database it has inserted zeros...
    I found that the first Query is not returning anything if i have set the Date condition in where clause...
    Regards
    Sweety
    Edited by: sweety_VA on Apr 25, 2011 7:32 AM

    Hi Sweety,
    Can you provide some more information? 
    The script for each of your queries.  (looking especially at how you are using single quotes around the Param properties for different data types)
    Are you using an Command SQL Query for the insert?
    Why are you using the Calculation action block instead of using the Expression Editor for the calculation?
    Regards,
    Mike

  • How to execute a Java method when row inserted into a database table?

    I have the need to fire off a java method when a row is inserted into a database table. I am unfortunately working with MySQL which just recently supported triggers but these new triggers can not execute a Java application on any event.
    What I am looking for is an event driven approach such that when a row is inserted into a specific table I can fire off a java method (sitting in a tomcat container) that will take the contents and send it to a web service.
    It has been mentioned that JMS may have the ability to poll and monitor a database table. Just wondering if anyone could point me in the right direction.
    thanks
    JavaTek

    A service handler might be the right way to run some code at the end of a service call (another way would be to make use of filters).
    First, make sure your static table is merged with ServiceHandlers.
    Secondary, change your custom method name into one that is not already in the service definition of COLLECTION_COPY_LOT (preferably a unique method name like collectionCopyLotLastAction that describes its purpose) and remove the following line from your code:
    m_service.doCodeEx("",this);Now create a service definition for COLLECTION_COPY_LOT in your custom component based on the original COLLECTION_COPY_LOT (copy paste from the original service definition) and add you own method collectionCopyLotLastAction as the last step in the service. Play with the load order to make sure CS is using your service definition of COLLECTION_COPY_LOT instead of the original.
    regards,
    Fabian

  • Inserting a record into Access database

    Hi guys i am having problem with the insertion of a record in to a Access database!!!!
    It is not given any exceptions or errors but simply does not insert it!!!
    Here is my code!!
    import java.sql.*;
    class access
    public static void main(String a[])
    // Set default values for the command line args\par
    Connection connection; // Connection to the database
    Statement statement; // Statement object for queries
    String user = "";
    String password = "";
    String url = "jdbc:odbc:db1";
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    try
    Class.forName(driver); // Load the driver
    connection = DriverManager.getConnection(url, user, password);
    if(a.length !=0)
    PreparedStatement ps = connection.prepareStatement("insert into search(Orgname,Website) values(?,?)");
    ps.setString(1,a[0]);     
    ps.setString(2,a[1]);
    int res = ps.executeUpdate();
    System.out.println("i am in" + " the output result no ="+res );
    ps.close();
    catch(ClassNotFoundException cnfe)
    System.err.println(cnfe); // Driver not found
    catch(SQLException sqle)
    System.err.println(sqle); // error connection to database
    -DK

    I'm not sure, but I think, linking your code against a library is considered as "using", not "deriving", since you don't change the library itself.
    It should not matter, whether you link staticly or dynamicly or only ship a file to use it with a program (like reading an image).
    Otherwise: how could anyone "use" a static library without linking his code to it?
    If - like you described - some features are "too low level" for your taste (I would feel similiar), I can only tell my experience:
    With InterBase you have a GPL'd DBMS which is available in fully mainted shape. You can download the executables and use it like a commercial DBMS - no touch with libraries or the sources, if you don't want.
    IBConsole is a tool that can be compared with MS SQLServer's Enterprise Manager, I think!
    InterClient/InterServer offers a JDBC type 3 driver.
    There are also some ODBC drivers for it at the market.
    This is real Open Source!
    What do you want more?

  • How to insert an array of number into access database?

    How can I insert an array of numbers(double) into an access database and later read them back to an array I labview. I don't have the Database Connectivity toolset. I would prefer using the LABSQL or other free solution. Any idea on how to solve this. I have tried LABSQL and SQL commands, but when I do that I have to convert the number to a string and then make a SQL-command string. Is there a way where I don't have to convert the number into a string?

    Hello,
    I am not familiar with LABSQL and we do not do any support on that particular product. However I still want to give you some information on how to proceed. You can either store the array to binary format and by doing this you can save an entire array to one single element of the database. The other alternative is of course to save one-to-one in other words one element of the array in one element in the database.
    More info can be found here:
    http://digital.ni.com/public.nsf/websearch/3FE68BBDA95E845986256DB4006A22C0?OpenDocument
    Have you checked MSDN for information regarding this? You might be able to find useful SQL code there to use.
    Regards,
    Jimmie A.
    Applications Engineer, National Instruments
    Regards,
    Jimmie Adolph
    Systems Engineer Manager, National Instruments Northern Region
    Bring Me The Horizon - Sempiternal

  • urgent insert Date with Time into Access Database

    i found the following codes from the forum to insert date into microsoft access database:
    java.sql.Date date = new java.sql.Date((new java.util.Date()).getTime())
    stmt.executeUpdate("INSERT INTO Testing " +"VALUES (#"+date+"#)");
    but i need to insert the date together with its time so may i know how can i do it?

    thanks alot i works... but it allow only one value to be inserted.
    so i try the codes below:
    Timestamp ts=new Timestamp(tryDate.getTime());
    PreparedStatement p = connection.prepareStatement("insert into testing values(?,?)");
    p.setTimestamp(1,ts);
    p.setString(2,theMsg.getContent());
    p.executeUpdate();
    and error is this:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106)
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:2564)
         at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
         at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
         at DBIncomingQueue.insertMessage(DBIncomingQueue.java:84)
         at DBIncomingQueue.main(DBIncomingQueue.java:213)

  • How to use DB toolkit to input string 255 into ACCESS Database

    I am converting an existing LV-Application from LV5.1.1 w/SQL toolkit to LV7.1 with DB-Conn. Toolkit.  One of the tables in my MS-Access database has a field of TYPE=memo (allows string lengths > 255 characters).  I can't seem to find how to insert this field in the DB-table using the "DB Tools Insert Data.VI" without getting an error.  I have tried converting the input string to a [U8] array, but that also doesn't work.  Just inputing the long string (390-chrs) also gives an error.  Reducing the string length to < 255 allows the new record to be input into the table without errors.  However, I need to be able to input the longer strings for the application to work.
    Does anyone have a solution to this problem.
    Thanks,
    Jim Cardinal

    Something like this
    David
    Message Edited by David Crawford on 01-12-2006 11:53 AM
    Attachments:
    Insert Text to Memo Using DBT.jpg ‏14 KB

  • Inserting into MsAccess Database

    Hi,
    I am having problem with inserting a row into the MsAccess Database. I am getting error like
    "SQLException: Occurred while performing Database Operations ---> method Main() java.sql.SQLException
    : [Microsoft][ODBC Microsoft Access 97 Driver] Syntax error in INSERT INTO statement.[Microsoft][ODB
    C Microsoft Access 97 Driver] Syntax error in INSERT INTO statement".
    My code is as under:
    please help me out.
    Smitha
    ==========================================
    package dao;
    import utils.GeneralFailureException;
    import dbConnection.dbConnection;
    import java.util.*;
    import java.sql.*;
    public class GeneralExpenses {
    dbConnection dbCon = new dbConnection();
    public GeneralExpenses() {
         super();
    public static java.sql.Timestamp getTstamp() {
    java.util.Date date = (Calendar.getInstance()).getTime();
    java.sql.Timestamp tStamp = new java.sql.Timestamp(date.getTime());
    System.out.println("The Time Stamp : " + tStamp);
    return tStamp;
    public void insertExpenseTable(String sExphead, double dAmount, String sMode)
         throws GeneralFailureException, SQLException, ClassNotFoundException {
         String inssql = "INSERT INTO EXPENSES(tnum, date , " + sExphead + ", " + sMode + ") VALUES(?,?,?,?)";
         Connection conn = null;
         PreparedStatement pstmt = null;
         try {
              conn = dbCon.getConnection();
              pstmt = conn.prepareStatement(inssql);
              pstmt.setInt(1, 100);
              pstmt.setTimestamp(2, getTstamp());
              pstmt.setDouble(3, dAmount);
              pstmt.setString(4, sMode);
              pstmt.executeUpdate();
         } finally {
              dbCon.closeAll(pstmt, conn);
    public static void main(String[] args) {
         try {
    GeneralExpenses ge = new GeneralExpenses();
         ge.insertExpenseTable("xxxxxxx", 250.35, "yyyyyyyy");
         System.out.println("worked");
         } catch(ClassNotFoundException sqlex) {
         System.err.print("SQLException: Occurred while performing Database Operations ---> method Main() " + sqlex);
         System.err.println(sqlex.getMessage());
         catch(SQLException sqlex) {
         System.err.print("SQLException: Occurred while performing Database Operations ---> method Main() " + sqlex);
         System.err.println(sqlex.getMessage());
    } catch(GeneralFailureException e) {
         System.err.print("GeneralFailureException: Occurred while Establishing Connection ---> method getConnection() " + e);
         System.err.println(e.getMessage());
    } catch(Exception e) {
         System.err.print("GeneralFailureException: Occurred while Establishing Connection ---> method getConnection() " + e);
         System.err.println(e.getMessage());

    I'm so happy to finally found the answer of my problem with that message Kurt.
    Thank you very much... !
    I will now remember that date cannot be the name of a field when using jdbc-odbc. I called my field TransDate and it is now working perfectly!

  • Any way to insert into a database clob other than streaming chars ?

    I have a jsp with a textarea object which I am inserting into an Oracle clob.
    I am using the thin driver.
    I have a problem in that if it is quite large (say over 2K) it falls over with "connection reset by peer" I think this may be because you aren't supposed to use this method with the thin driver, but I don't want to use OCI.
    So is there any other way to insert my text into the database without having to explicitly select the row first for update as this is essentially a new insert so doing it like this I would have to first of all insert the other columns then reselect the row for update of the clob.
    Thanks.

    Most, if not all, database management systems have their own features to read text data from files.  You may prefer that functionality over piping the data through ColdFusion and the database drivers.
    <cffile...> can "read" .doc and .pdf file as in it can read the file from the file system as the binary data they are, but that does not extract the text from the content.  You can do some stuff with CFML to read the text in a pdf file with the <cfpdf...> and related tags and functions.  I'm not aware of similar CFML features that work with doc files, but I know of Java tools that do such as POI.  These are usually fairly straight forward to tap into with ColdFusion.

  • Problem inserting into tables

    Hello All, I hope that someone out there may be able to shed some light on my problem!!
    I have developed a series of JSP pages for my web site (using Tomcat 4.1)to allow a Customer to register themselves with the site. I have developed 3 corresponding JavaBeans to hold the details that the customer enters; a Customer bean, an Address bean and a Payment bean. In my database (MySQL) i have tables corresponding to each of these beans, which simply take the data inserted into a field by the user and create a new instance of each.
    Now, the above is all working fine and the database tables populate themselves exactly as they should; however, to allow a customer to add more than one address, or more than one payment method, I have developed the relationship tables 'hasaddress' and 'haspaymentdetails' to store the relevant id numbers in the database (i.e. hasaddress stores a customerid from the customer bean and an addressid from the address bean).
    Finally, i get round to my question!!..
    I am using the following jsp code to insert data into one such table:
    <------------------------------------------------------------------->
    <jsp:useBean id="registration" class="projectBeans.RegistrationBean" scope="session"/>
    //set the connection
    registration.setConnection(c);
    //retrieve the customer attribute
    projectBeans.Customer customer = (projectBeans.Customer)session.getAttribute("newCust");
    //retrieve the address attribute
    projectBeans.AddressBean address = (projectBeans.AddressBean)session.getAttribute("newAddr");
    //use the addCustomer method in the bean to create a new customer     
    registration.addCustomer(customer);
    //ditto for address
    registration.addAddressDetails(address);
    //populate the hasaddress table with the correct ids
    String table = "hasaddress";
    int customerid = customer.getCustomerId();
    int addressid = address.getAddressId();
    registration.updateRelationship(table, customerid, addressid);Both the addCustomer and addAddressDetail methods work fine, so below is just the code for updateRelationship method in the registrationBean:
    public void updateRelationship(String table, int id1, int id2) throws SQLException
       sta = c.prepareStatement("INSERT INTO "+table +" VALUES(?,?)");
       sta.setInt(1, id1);
       sta.setInt(2, id2);
       sta.executeUpdate();
    }I would expect this method to retrieve the newly assigned customer and address ids and enter them into the hasaddress table; however, when the page compiles and i look at the table it enters 0 for each of the fields (when it should, for example be entering 14 and 16):
    ----------+
    | cid | aid |
    ----------+
    | 0 | 0 |
    ----------+
    so my question is: does anyone have an idea as to why this is happening, or what may be wrong with my code for this to occur?
    Alternatively, am i being dumb and is there some way of getting MySql to handle the updates to the relationship table internally?
    Thanks in advance for any ideas,
    Cheers

    Try to specify you database field as SQL need field names to do updating
    sta = c.prepareStatement("INSERT INTO "+table + "("+ id1+","+id2+ ")"+ VALUES(?,?)");

  • Servlet not inserting into Access Databse. help please

    I have the following code which is inserting three fields into a database. The database name is contacts.mdb, and the table is contacts. I have setup the ODBC connection on the server, of which I have both IIS and Tomcat running. The form.html that I am accessing is on the tomcat server root and that code is below as well. After hitting the submit button on the form I get forwarded to the servlet, and the page is blank. However, when I open the database, no updates have occured. Please help. I hope I have provided enough detail. Thanks so much.
    -------- servlet code start --------------
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class WebServlet
    extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
    IOException {
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String sourceURL = "jdbc:odbc:terry_web_contacts";
    Connection databaseConnection = DriverManager.getConnection(sourceURL);
    Statement stmt = databaseConnection.createStatement();
    String jname = request.getParameter("Name");
    String jemail = request.getParameter("Email");
    String jcomments = request.getParameter("Comments");
    String sqlInsertString ="INSERT INTO contacts (name, email, comments) VALUES ('" + jname +"', '" jemail "', '" + jcomments + "')";
    stmt.executeUpdate(sqlInsertString);
    databaseConnection.close();
    catch(ClassNotFoundException cnfe)
    System.err.println("Error loading Driver");
    catch (SQLException sqle){
    System.err.println("SQL Error");
    ---------- servlet code end ---------------------
    ---------- html form code start ------------------
    <HTML>
    <HEAD>
    <TITLE>Example</TITLE>
    </HEAD>
    <BODY BGCOLOR="WHITE">
    <TABLE BORDER="2" CELLPADDING="2">
    <TR><TD WIDTH="275">
    <H2>I'm a Simple Form</H2>
    <FORM METHOD="POST" ACTION="/servlet/WebServlet">
    <p>
    <INPUT NAME="Name" TYPE="TEXT" id="Name" SIZE=30>
    </p>
    <p>
    <INPUT NAME="Email" TYPE="TEXT" id="Email" SIZE=30>
    </p>
    <p>
    <textarea name="Comments" id="Comments"></textarea>
    </p>
    <P>
    <INPUT TYPE="SUBMIT" VALUE="Click Me">
    <INPUT TYPE="RESET">
    </FORM>
    </TD></TR>
    </TABLE>
    </BODY>
    </HTML>
    ------------- html code end ------------------

    Okay, here is my modified code. However, I catch a sql error. It prints out "sql error". If I try to isolate the different lines of code with try catch blocks, the compiler says it does not recognize the symbols for example stmt, or databaseConnection. Arggh, what can I do? Help please.
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class WebServlet
        extends HttpServlet {
      public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException,IOException
         PrintWriter out = response.getWriter();
         String jname = (String) request.getParameter("Name");
         String jemail = (String) request.getParameter("Email");
         String jcomments = (String) request.getParameter("Comments");
    try
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException e)
         out.println("class error");
    try
         Connection databaseConnection = DriverManager.getConnection("jdbc:odbc:terrycontacts");
         Statement stmt = databaseConnection.createStatement();
         String sqlInsertString ="INSERT INTO contacts(name,email,comments) VALUES('"+jname+"','"+jemail+"','"+jcomments+"')";
         stmt.executeQuery(sqlInsertString);
         databaseConnection.commit();
         databaseConnection.close();
    catch(SQLException e)
         out.println("sql error");
         out.close();
    }

  • UDF JDBC -- want to insert into a database

    Hi experts,
    I need to insert into a DB using a UDF. I have written the UDF but the problem is it works fine for a select query and when i replace the query with insert, it fails.
    the JDBC CC says invalid SQL query.
    The 2 queries are :
    //insertQuery= "insert into TABLENAME (COLUMNNAME) values ('"VAR"')";
    //insertQuery= "select count(*) from TABLENAME";
    accessor = LookupService.getDataBaseAccessor(channel);
    resultSet = accessor.execute(insertQuery);
    Also if I execute the insert query in DB it works fine.
    Please advise.

    It is a very simple thing i am doing..........................
    i have a source structure in which the first field of the source is the input to the first field of the target.
    there is a UDF in between which inserts the first source field. the UDF has the channel specified which is  JDBC.
    I was just running it thru the display queue (in MM) at the  and checking the communication channel. It gets errored out......... saying invalid SQL statement. But for select query it works fine

Maybe you are looking for

  • After Updating to iOS 7.0.4, Dictation Is Barely Working Again!

    Well, after updating to iOS 7.0.4 today, dictation is barely working again! After the previous problems with Dictation were fixed with 7.0.3, it was working really well for the last few weeks, but for some reason, it seems the new 7.0.4 update has me

  • Fonts problem in Preview, but not Adobe Reader

    Hi.  I am preparing content within Sibelius (music writing software) - I use v.6.2 on my PC and create PDF files using Nitro PDF driver. Nearly all the people using my files are Mac users (on whose behalf I am writing!) and who have never had a probl

  • How do i reset an ipod touch

    Does anybody know how to reset an ipod touch 4?

  • Problems with the dbms_alert Package

    Hello everybody, I am having some problems while using the ORACLE dbms_alert package, problems which are not documented, at least anywhere that I can tell. Namely the table dbms_alert_info, which holds the registered alerts of the coresponding sessio

  • Third party subcontracting

    Hi Expert, I have some subcontractor related problem. In subcontracting process component to be supplied by " Third party" not by our company,we create the purchase order and given the delivery address to the subcontractor address. in this process wh