Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19113

Re: problem in inserting record in ms access.

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: problem in inserting record in ms access.
Date 2012-10-04 23:24 +0000
Organization UK Free Software Network
Message-ID <k4l5r9$2rp$1@localhost.localdomain> (permalink)
References <110ed4b2-e29a-4c6d-81df-3eee8e532a7c@googlegroups.com> <506e0132$0$289$14726298@news.sunsite.dk>

Show all headers | View raw


On Thu, 04 Oct 2012 17:35:39 -0400, Arne Vajhøj wrote:

> On 10/4/2012 12:47 AM, Navnath Gadakh wrote:
> I will not recommend the JDBC ODBC bridge unless you are absolutely
> forced to use it.
> 
The OP mentioned (in the title) that he is using MS Access. Is there a 
JDBC driver for it?
 
> Always print the exception.
> 
And always print all chained SQLExceptions in the chain or you're likely 
to miss seeing something you need to read.

>>              rs.updateString("mobile","99854874154"); rs.insertRow();
> 
> I would suggest using plain INSERT instead of this.
>
Agreed. I didn't mention it because the OP may have thought he'd save 
time this way. 

However he could be surprised: when I've done this in a GUI program I've 
always made the change using INSERT/UPDATE/DELETE and then reloaded the 
JTable's model from the database. When I wrote one these programs, I 
thought there might be a delay while the table reloaded since there are 
10-12K rows in the table it updates, but to my surprise the displayed 
section of the Jtable is redisplayed in a second or two to show the 
change. Equipment: the Java program is on a 1.3 GHz Core Duo laptop that 
talks to the database over a 10 Mbs local LAN. The database was initially 
PostgreSQL 7.x on an 866MHz 512MB P3 box and is currently PostgreSQL 9.x 
on a 3GHz 4GB Athlon Duo. Both computers run Linux and, surprisingly, I 
haven't noticed that moving the database to the faster box made much 
difference to the speed of this app.
   
> Don't do such heavy work in the constructor.
>
Yep, and get into the habit of putting the session startup and close 
operations into separate methods: you only need to open the connection 
once at the start of the program and close it at the end of the program 
run.

Consider preparing the SQL statement(s) as part of startup. Apart from 
making each SQL call faster, you'll also protect your program from SQL 
injection attacks. The most a database access method should do is issue 
the SQL call, use the ResultSet to retrieve the results and then close 
the ResultSet. Similarly for INSERT/DELETE/UPDATE operations.  


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

problem in inserting record in ms access. Navnath Gadakh <navnathgadakh@gmail.com> - 2012-10-03 21:47 -0700
  Re: problem in inserting record in ms access. Martin Gregorie <martin@address-in-sig.invalid> - 2012-10-04 19:39 +0000
  Re: problem in inserting record in ms access. Arne Vajhøj <arne@vajhoej.dk> - 2012-10-04 17:35 -0400
    Re: problem in inserting record in ms access. Martin Gregorie <martin@address-in-sig.invalid> - 2012-10-04 23:24 +0000
      Re: problem in inserting record in ms access. Arne Vajhøj <arne@vajhoej.dk> - 2012-10-05 20:27 -0400
        Re: problem in inserting record in ms access. Martin Gregorie <martin@address-in-sig.invalid> - 2012-10-06 11:36 +0000
          Re: problem in inserting record in ms access. Arne Vajhøj <arne@vajhoej.dk> - 2012-10-06 09:08 -0400
  Re: problem in inserting record in ms access. Roedy Green <see_website@mindprod.com.invalid> - 2012-10-04 20:33 -0700
    Re: problem in inserting record in ms access. Lew <lewbloch@gmail.com> - 2012-10-05 10:48 -0700

csiph-web