The Artima Developer Community
Sponsored Link

Java Answers Forum
Java and Ms Access database integrating together

4 replies on 1 page. Most recent reply: May 8, 2005 10:37 PM by M. Eric DeFazio

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
borce ivanovski

Posts: 3
Nickname: borce
Registered: Apr, 2005

Java and Ms Access database integrating together Posted: Apr 26, 2005 3:02 PM
Reply to this message Reply
Advertisement
Hello everyone,

I have two problems:
1. I need to create tool that will create a test database and later on to populate it. The first problem is connected with creating the file. I do not know whether this is possible or not, but I want to create a file in which later on I can create tables and insert some values in the tables.
2. In this problem I want to input meaningfull values in the database columns? I do not know how this could be done.

Also at the moment I am have created the application and connect the application with a database file created from MS Access, with ODBC driver through the Control Panel.. What I mean to do is to create dinamicaly file according to the user input, and to populate that file with meaningfull data(values) later on. This is all done automatically, the user do not have to insert the values in the database, but through For loop at the moment I am inserting some kind of values, rows in the database, according the users input.

Any tips and help regarding any of the two above problems will be appreciated.

Thanks to everyone,
Borce.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Java and Ms Access database integrating together Posted: Apr 26, 2005 10:53 PM
Reply to this message Reply
I don't think you can create a Database using the ODBC driver.

Create an empty Database using access and save it as template.mdb

Then, when you want to create a new DB, copy the template in the desired location.

Creating tables: Use SQL commands.
create table tbname (col1 Char(40), col2 Single, ...)
alter tbname add col4 Bit
.
.
.

Filling with values:
I don't know what your teacher expects when he says meaningfull values, just insert random values wich sound realistic.

borce ivanovski

Posts: 3
Nickname: borce
Registered: Apr, 2005

Re: Java and Ms Access database integrating together Posted: May 4, 2005 6:04 AM
Reply to this message Reply
Ok thanks for the help.

Can you just give me some info on how to input data from file? Thanks to everyone.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Java and Ms Access database integrating together Posted: May 5, 2005 4:30 AM
Reply to this message Reply
I don't know the format of your file.

Use a BufferedReader to read the lines.
Then evaluate the lines.


1. Sql-Syntax for appending data to a table:
insert into tbname (columnName1, columnName2, columnName3, columnName4) values (123, 'text', null, true)

2. Sql-Syntax for editing data
update tablename set columnName1 = 123, columnName = 'text' where conditionColumnName1 = false and conditionColumnName2 = 3

M. Eric DeFazio

Posts: 10
Nickname: defazio
Registered: May, 2005

Re: Java and Ms Access database integrating together Posted: May 8, 2005 10:37 PM
Reply to this message Reply
I might have stumbled apon exactly what your looking for...

check out http://jackcess.sourceforge.net/

Here's some sample code noted from the project :..SNIP
# Creating a new table and writing data into it:

Database db = Database.create(new File("new.mdb"));
Column a = new Column();
a.setName("a");
a.setSQLType(Types.INTEGER);
Column b = new Column();
b.setName("b");
b.setSQLType(Types.VARCHAR);
db.createTable("NewTable ", Arrays.asList(a, b));
Table newTable = db.getTable("NewTable");
newTable.addRow(new Object[] {1, "foo"});

# Copying the contents of a JDBC ResultSet (e.g. from an external database) into a new table:

Database.open(new File("my.mdb")).copyTable("Imported", resultSet);

# Copying the contents of a CSV file into a new table:

Database.open(new File("my.mdb")).importFile("Imported2", new File("my.csv"), ",");

...END SNIP

Flat View: This topic has 4 replies on 1 page
Topic: TIJ Example c08:Callbacks.java Previous Topic   Next Topic Topic: KeyTyped Event

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use