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

MS-Access and JDBC

2 views
Skip to first unread message

stil...@ryuji.net

unread,
Aug 4, 2001, 1:32:52 PM8/4/01
to
Hello All!

I think my questions are stupid for most of you, but I am totally new to
JDBC, so please forgive me asking the stupid questions. I want to
connect to my MS-Access running under WIn2000 from Java application
using JDBC. I want to use JDBC-ODBC bridge which came with JDK1.3.

After I execute a statement

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

I execute a following statement. I have test.mdb file.

Connection con = DriverManager.getConnection("jdbc:odbc:test");

Then I get following errors.

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name
not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize
(JdbcOdbcConnection.java:320)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)

Could somebody tell me how to connect MS-Access? I am running on my PC
(locally). And When I try to connect, does Access have to running?


Thanks in advance.

Rene Pijlman

unread,
Aug 4, 2001, 2:39:10 PM8/4/01
to
stil...@ryuji.net schreef:
[MS Access via JDBC-ODBC bridge]

>I execute a following statement. I have test.mdb file.
>Connection con = DriverManager.getConnection("jdbc:odbc:test");

You need to create an ODBC data source on the Windows machine where
this code runs. See "data sources" in Administrative Tools.

--
Vriendelijke groet,
René Pijlman <rpij...@spamcop.net>

Wat wil jij leren?
http://www.leren.nl/

stil...@ryuji.net

unread,
Aug 4, 2001, 3:28:45 PM8/4/01
to
Thanks for the response. I created the data sourse. What I did was
following.

From Data Source in Administrative Tools, I picked User DNS tab and I
selected MS Access Database.
Then I clicked Configure and I clicked Select.
After that, I chose E:\db\test.mdb.

Is this a correct way to create data source?
I still get following error messages.

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name
not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize
(JdbcOdbcConnection.java:320)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)


Thanks in advance.


In article <u5gomt0tm5fc18ht7...@4ax.com>,
reage...@de.nieuwsgroep says...

SnedBlaster

unread,
Aug 4, 2001, 4:07:21 PM8/4/01
to
Then double click Data Sources (ODBC)

pick the button that says add.

Then select Microsoft Access Driver (*.mdb)

Then click finish

Now enter any Name that you would like to call the DataBase. This is what
you put in the DataBase Name field.

Next in the DataBase section, click on select, and pick your .mdb file.

This is how I did it.

<stil...@ryuji.net> wrote in message
news:MPG.15d616f04...@news-byoa.prodigy.net...

Rene Pijlman

unread,
Aug 4, 2001, 4:09:06 PM8/4/01
to
stil...@ryuji.net schreef:

>Is this a correct way to create data source?

Check your setup with this documentation:
http://home-1.worldonline.nl/~bmc88/java/jdbc/
http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html

Tom

unread,
Aug 4, 2001, 9:42:00 PM8/4/01
to
use System DNS
and make sure the data source name is exactly the same as in your code:
ie for your example: test


<stil...@ryuji.net> wrote in message
news:MPG.15d616f04...@news-byoa.prodigy.net...

: Thanks for the response. I created the data sourse. What I did was

: >


stil...@ryuji.net

unread,
Aug 5, 2001, 12:57:29 AM8/5/01
to
Thank you very much for answering my question. Finally I successfully
connect my DB. And I can query the DB. However, I can't update. I
tried to insert a new row to the DB using following statement.

Statement stm = con.createStatement();
String val = "INSERT INTO testTable VALUES(\"111\", \"John\", \"New
York\", \"123-4567\");";
stm.executeUpdate(val);

However, I got folling errors. Why it says "Too few parpameters"?
Could anybody tell me what wrong is?


java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few
parameters. Expected 4.


at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)

at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
at sun.jdbc.odbc.JdbcOdbcStatement.execute
(JdbcOdbcStatement.java:314)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate
(JdbcOdbcStatement.java:264)


And what JDBC book do you recommend?

Thanks in advance.

Rene Pijlman

unread,
Aug 5, 2001, 5:07:36 AM8/5/01
to
stil...@ryuji.net schreef:

> String val = "INSERT INTO testTable VALUES(\"111\", \"John\", \"New
>York\", \"123-4567\");";

What does your table look like?

>And what JDBC book do you recommend?

http://java.sun.com/docs/books/jdbc/
Very thorough.

stil...@ryuji.net

unread,
Aug 5, 2001, 11:19:49 AM8/5/01
to
In article <p33qmtkp9iosjhp6o...@4ax.com>,
reage...@de.nieuwsgroep says...

> stil...@ryuji.net schreef:
> > String val = "INSERT INTO testTable VALUES(\"111\", \"John\", \"New
> >York\", \"123-4567\");";
>
> What does your table look like?
>

My table has four columns which are following.

ID (text), name (text), address (text), phone (text)

Thanks

Aloundeth Oupraxay

unread,
Aug 5, 2001, 1:53:37 PM8/5/01
to
Hi,

Try this,
String val = "insert into testTable(id, name, address, phone)
values('111','John','new','123-4567')";
I hope that's correct...

Cheers,
Al,

<stil...@ryuji.net> wrote in message
news:MPG.15d72e127...@news-byoa.prodigy.net...

0 new messages