XML/Java

M

Maxi

Hello,
I have this XML file below and I want to read the data from the XML file in
my java code when I connect to my database in my java code.
How do i do that ?

---XML File
<db>
<databaseName>opsa</databaseName>
<username>User</username>
<password>Pass</password>
</db>

------database.java
public void ConnectToDatabase()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn= DriverManager.getConnection ("jdbc:eek:dbc:eek:psa", "", "");
stmt = conn.createStatement();
}
catch (Exception ex){}
}
 
A

Andrew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Maxi wrote:
| Hello,
| I have this XML file below and I want to read the data from the XML
file in
| my java code when I connect to my database in my java code.
| How do i do that ?
|
| ---XML File
| <db>
| <databaseName>opsa</databaseName>
| <username>User</username>
| <password>Pass</password>
| </db>
|
| ------database.java
| public void ConnectToDatabase()
| {
| try
| {
| Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
| conn= DriverManager.getConnection ("jdbc:eek:dbc:eek:psa", "", "");
| stmt = conn.createStatement();
| }
| catch (Exception ex){}
| }
|
|

You could read up on the XML SAX/DOM tutorials which will show you how
to do it. Do you really need to specify these details in an XML file
though, wouldn't a normal properties file do the job, and it is much
simpler.?

- --
[A n d r e w]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/gC8lx4nopx2ZsVURAktIAJwNoJiOgEz2fEJGgoqJ2frCqSfiMACfRVok
PHzPNBqqsUhsadGVzpScvtM=
=+IL2
-----END PGP SIGNATURE-----
 
S

servee

You could read up on the XML SAX/DOM tutorials which will show you how
to do it. Do you really need to specify these details in an XML file
though, wouldn't a normal properties file do the job, and it is much
simpler.?
and faster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top