Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inserting a record into a access db with jdbc

0 views
Skip to first unread message

halve

unread,
Apr 2, 2002, 9:57:09 AM4/2/02
to
Hi everyone, hoping yall might beable to give me a hand. I am trying
to insert serveral fields into a access database. The fields are
being held in JTextFields.


This is what my code looks like:

public void userAdd()
{
try
{
stmt = con.createStatement(rs.TYPE_SCROLL_SENSITIVE,
rs.CONCUR_UPDATABLE);

rs = stmt.executeQuery("SELECT * FROM TIMELOGGER");
stmt.executeUpdate("INSERT INTO TIMELOG" +
"VALUES 'test','test',#10/0/2002#,#7:00#,#7:00#,#7:00#,#7:00#,#7:00#,'x',20");
}
catch(Exception e){}
}

Right now im using temp data, somereason this will not work. Are
there anyways that a insert can be made simpler?

Halve

Davide Bianchi

unread,
Apr 2, 2002, 11:39:30 AM4/2/02
to
halve wrote:

> stmt.executeUpdate("INSERT INTO TIMELOG" +
> "VALUES 'test','test',#10/0/2002#,#7:00#,#7:00#,#7:00#,#7:00#,#7:00#,'x',20");


10/0/2002 ?

use a preparedStatement and setTime() setDate() to fill in all the
required parameters.

Davide

Ingo Pakleppa

unread,
Apr 3, 2002, 3:59:29 AM4/3/02
to

First, as Davide pointed out, use a PreparedStatement. Second, in the
situation you have here, one common mistake is to forget the space
between the TIMELOG and the VALUES. Remember that the string in the
first line and the string in the second line are concatenated, so
where you meant to write "INSERT INTO TIMELOG VALUES ..." you actually
may have "INSERT INTO TIMELOGVALUES ..."

which of course is not quite the same thing!

Ingo

PimentoTR6

unread,
Apr 4, 2002, 11:44:19 PM4/4/02
to
>>Hi everyone, hoping yall might beable to give me a hand. I am trying
>>to insert serveral fields into a access database. The fields are
>>being held in JTextFields.
>

And you have a driver that supports JDBC2? Such beasts are available, but not
easily.

Steve

kelzam

unread,
Apr 5, 2002, 7:57:55 PM4/5/02
to
Hi,

CONCUR_UPDATABLE option is not support for access database.


Cheers,
Kel


"halve" <hal...@hotmail.com> wrote in message
news:5beb0f9e.02040...@posting.google.com...

1

unread,
Apr 9, 2002, 8:20:46 AM4/9/02
to
Kel,

How can one verify this since:

dbmd.supportsResultSetConcurrency(1008) returns True for MS Access db driver
version 2.0001 (04.00.4403)

I'm trying someting different with Access but having problems as well...

Thanks,
Pete

"kelzam" <kel...@pacific.net.sg> wrote in message
news:a8lh5p$45d$1...@newton.pacific.net.sg...

PimentoTR6

unread,
Apr 9, 2002, 10:36:21 AM4/9/02
to
I think you mean:
dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

but, nonetheless, I tried that with my Access ODBC driver and the Sun JDBC
bridge driver and got "true," even though I know that driver combination
doesn't support the operation.

I access Access using the IDS Server with it's drivers and everything works
jsut fine.

Steve

Pete

unread,
Apr 9, 2002, 12:37:51 PM4/9/02
to
Not sure I see the difference, but How do you know that particular
operations aren't supported by the driver?

"PimentoTR6" <pimen...@cs.compost> wrote in message
news:20020409103621...@mb-mo.news.cs.com...

PimentoTR6

unread,
Apr 9, 2002, 3:50:16 PM4/9/02
to
>Not sure I see the difference,

If you mean from
dbmd.supportsResultSetConcurrency(1008)
to
dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

Well, the second will compile, the first won't, all other issues about using
named constants vs their actual values aside.

>How do you know that particular
>operations aren't supported by the driver?

The first clue I had was when it threw an exception:

java.lang.NullPointerException
at
sun.jdbc.odbc.JdbcOdbcBoundCol.setRowValues(JdbcOdbcBoundCol.java:240
)
at
sun.jdbc.odbc.JdbcOdbcResultSet.updateChar(JdbcOdbcResultSet.java:376
7)
at
sun.jdbc.odbc.JdbcOdbcResultSet.updateString(JdbcOdbcResultSet.java:3
257)
at JDBCConstants.main(JDBCConstants.java:22)

When I tried to call updateString.

I got a different exception when I tried absolute(int):

java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
at
sun.jdbc.odbc.JdbcOdbcResultSet.absolute(JdbcOdbcResultSet.java:2358)

at JDBCConstants.main(JDBCConstants.java:18)

When I specifically asked for TYPE_SCROLL_SENSITIVE

All that aside, rereading the original post, it isn't a concurrency issue at
all, since the OP isn't using moveToInsertRow and insertRow to add the
data--but the somewhat typo-laden:

rs = stmt.executeQuery("SELECT * FROM TIMELOGGER");
stmt.executeUpdate("INSERT INTO TIMELOG" +
"VALUES
'test','test',#10/0/2002#,#7:00#,#7:00#,#7:00#,#7:00#,#7:00#,'x',20");

Assuming the typos were in transcription and not in the true code, and that all
the fields are where and what they are supposed to be, the only other thing I
can think of is to do rs.close() first (or for that matter, don't even run the
select query if the data isn't going to be used).

Steve

kelzam

unread,
Apr 10, 2002, 4:50:14 AM4/10/02
to
Hi,

I use JBuilder. The debugger reflect that java.sql.SQLException:
[Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented.
I discover the moment CONCUR_UPDATABLE is set, my code will not work.


Cheers,
Kel

"1" <1@1> wrote in message news:a8umav$ao...@shark.pwgsc.gc.ca...

Sum Ting Wong

unread,
Apr 10, 2002, 10:05:18 PM4/10/02
to
use a different database.. or rethink the update :)

"kelzam" <kel...@pacific.net.sg> wrote in message

news:a90ub7$lp9$1...@newton.pacific.net.sg...

0 new messages