Home > Archive > Java Help > March 2004 > getting started with databases
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
getting started with databases
|
|
| Agata Staniak 2004-03-28, 12:01 am |
| Hey!
I need to write a simple applet that will use a simple database (actually, a
Microsoft Access file - db1.mdb).
I don't know much about databases, I only know how to write simple SQL
queries (I only used PHP + MySQL so far).
And as I read in Sun's JDBC tutorial, before establishing a connection I
have to load some driver.
So I have some questions:
1) What is the name of the driver for mdb files?
2) Where can I get it (or maybe it is automatically installed with JDK 1.4)?
3) Do I need anything more to establish a connection with the database?
If anyone could send me a simple snippet that connects to an mdb file, makes
a query (something like "SELECT * FROM table;") and disconnects - it would
be great - I totally lost my way :-(
Thanks in advance
--
Agata Staniak
| |
| Christophe Vanfleteren 2004-03-28, 12:01 am |
| Agata Staniak wrote:
> Hey!
> I need to write a simple applet that will use a simple database (actually,
> a Microsoft Access file - db1.mdb).
> I don't know much about databases, I only know how to write simple SQL
> queries (I only used PHP + MySQL so far).
> And as I read in Sun's JDBC tutorial, before establishing a connection I
> have to load some driver.
>
> So I have some questions:
> 1) What is the name of the driver for mdb files?
> 2) Where can I get it (or maybe it is automatically installed with JDK
> 1.4)? 3) Do I need anything more to establish a connection with the
> database?
>
> If anyone could send me a simple snippet that connects to an mdb file,
> makes a query (something like "SELECT * FROM table;") and disconnects - it
> would be great - I totally lost my way :-(
>
> Thanks in advance
>
http://java.sun.com/docs/books/tutorial/jdbc/
--
Kind regards,
Christophe Vanfleteren
| |
| Christophe Vanfleteren 2004-03-28, 12:01 am |
| Agata Staniak wrote:
> Hey!
> I need to write a simple applet that will use a simple database (actually,
> a Microsoft Access file - db1.mdb).
> I don't know much about databases, I only know how to write simple SQL
> queries (I only used PHP + MySQL so far).
> And as I read in Sun's JDBC tutorial, before establishing a connection I
> have to load some driver.
>
> So I have some questions:
> 1) What is the name of the driver for mdb files?
> 2) Where can I get it (or maybe it is automatically installed with JDK
> 1.4)? 3) Do I need anything more to establish a connection with the
> database?
>
> If anyone could send me a simple snippet that connects to an mdb file,
> makes a query (something like "SELECT * FROM table;") and disconnects - it
> would be great - I totally lost my way :-(
>
> Thanks in advance
>
For accessing an Acces DB, you need to use the jdbc-odbc bridge. You load
the correct driver like this:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
The driver comes with the JRE, so you don't need to install anything extra.
But where is your Acces file located? If it's also on the client, you'll
need to get the applet signed, because otherwise, you have no acces to the
file system.
If it's on the server the applet came from, your users would need to setup
the odbc connection to it themselves.
What are your exact needs? Maybe an embedded DB like HSQL could suit your
needs better.
--
Kind regards,
Christophe Vanfleteren
| |
| Agata Staniak 2004-03-28, 12:01 am |
| > What are your exact needs? Maybe an embedded DB like HSQL could suit your
> needs better.
The html document, the applet & the access db are on the server (now it's
my local machine, on Friday it'll be school's laboratory). I have no idea
what HSQL is. And I have no idea what is installed in the lab, I only know
there's JDK 1.4
| |
| Agata Staniak 2004-03-28, 10:36 pm |
| Hey, I've managed to connect to my Access database. And everything works
well as long as I use JBuilder's applet Viewer. But when I run the same
applet even on my my local machine, an exception occurs when loading the
jdbc:odbc driver:
//Initialize the applet
public void init()
{
try
{
jbInit();
//this works in my Boland's viewer but throws an exception in MSIE -
why?
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
e.printStackTrace();
}
}
Anyone got any ideas? Thanks in advance.
| |
|
|
| Agata Staniak 2004-03-29, 5:39 am |
| > Or perhaps a SecurityAccessException?
Yes, exactly.
> for the latter, check here..
> <http://java.sun.com/developer/techn...curity/applets/>
>
> Long story short. You will not be able to
> access a DB from an applet unless you sign it
> or set the security settings of each browser.
Thanks.
| |
| Tony Morris 2004-03-29, 7:35 am |
| > Long story short. You will not be able to
> access a DB from an applet unless you sign it
> or set the security settings of each browser.
<FYI>
Or the database to be accessed resides on the host from which the applet
originated.
</FYI>
| |
| Andrew Thompson 2004-03-29, 9:46 am |
| On Mon, 29 Mar 2004 11:44:29 GMT, Tony Morris wrote:
>
> <FYI>
> Or the database to be accessed resides on the host from which the applet
> originated.
> </FYI>
Good point.
I was a bit 'broad and sweeping' in my
original statement. Of course, with the
lack of exact error messages, I felt I
had 'been given licence' - well I took
it anyway. ;-)
--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
| |
| Agata Staniak 2004-03-29, 11:50 am |
| > Or the database to be accessed resides on the host from which the applet
> originated.
So once again: Yes, the database is on the same machine as the html document
with the applet.
Do I still need a certificate then? When the applet is downloaded by a
client and is run in the client's browser, how will it "know" it should use
the database on the server, not on the client's computer? Does the jdbc-odbc
bridge support that? Or do I need a different driver? And is it included in
the JDK 1.4 or do I have to download it separately?
|
|
|
|
|