Solved

creating dsn dynamically !

Posted on 2001-06-20
6
696 Views
Last Modified: 2008-03-10
can any one tell me whether it is possible to create a dsn dynically from java program !! both either file or system dsn !! i  have to implement automated code for doing creation of dsn dynamically !!

awaiitng quick replies
0
Comment
Question by:hemanth_ag
6 Comments
 
LVL 1

Expert Comment

by:tonus
ID: 6213517
As per my knowledge, you cannot create a DSN from a java program. Instead of that you can go for DSN less connection using Type 4 driver in java. Here is the list of drivers for java

http://ourworld.compuserve.com/homepages/Ken_North/jdbcvend.htm

http://www.javaworld.com/javaworld/jw-07-2000/jw-0707-jdbc_p.html


0
 
LVL 4

Accepted Solution

by:
rdov earned 25 total points
ID: 6214112
There is no pure Java way to do this, but you can access the system registry directly:

Under Windows this information is contained in the system
registry, in the key:
"HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"

("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" contains the User DSNs)

You can iterate through all values in this key to get the names of every System DSN (indicated below as <DSNname>).
The specifics of every System DSN are contained in the keys: "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<DSNname>"
Use Regedit application.

If you want to access the registry, you will need to use JNI or an equivalent non-portable feature.  

You can get a free Java JNI package to manipulate the MS Windows Registry from
http://www.trustice.com/java/jnireg/

If you don't mind locking yourself into Microsoft's VM you can use the com.ms.lang package which contains these classes:
  RegKey
  RegKeyEnumValue
  RegKeyValueByteArray
  RegKeyValueInt
  RegKeyValueString
  RegKeyException
  RegKeyValueEnumerator
  RegQueryInfo

See
http://www.microsoft.com/java/sdk/20/
http://www.microsoft.com/java/sdk/20/packages/lang/default.htm
0
 
LVL 2

Assisted Solution

by:vpadma
vpadma earned 25 total points
ID: 6214527
Hi,
Assuming you have the requires driver installed,
there are two things you should have your program do:

1.Make registry entries int he appropriate directories:
This is the contents of the .reg file that you can write to and run it using the java program. This
assumes the driver you wanna use is SQl server. Here is an example. Replace the values of these keys
as appropriate.
Contents of test.reg file:

REGEDIT4

[HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\test]
"Driver"="C:\\WINNT\\System32\\sqlsrv32.dll"
"Description"="test"
"Server"="(local)"
"UseProcForPrepare"="Yes"
"OEMTOANSI"="No"
"Trusted_Connection"=""
"LastUser"=""

2. Write to C:\WINNT\ODBC.ini file:
(This is not very essential. Depends on your usage. Since windows now replaces the use of .ini files
with registry entries, most of the sophisticated applcations would work just with the registry entries.
This might mostly be just for backward compatibility.)
This file has two parts to it. One is [ODBC 32 bit Data Sources] part and second is [MS Access 97 Database]
(this  one is so that you can access it using access.)
There are two lines you should add:
Say, you have added a DSN names TEST which points to a SQL server driver, then you should add the name
test = driver name under the first part of the file.
(i will mark the begining of those lines in the sample .ini file below with an arrow (-->). Obviously
the actual file should have this arrow removed!!!)
ODBC.ini:

[ODBC 32 bit Data Sources]
MS Access 97 Database=Microsoft Access Driver (*.mdb) (32 bit)
dBASE Files=Microsoft dBase Driver (*.dbf) (32 bit)
Excel Files=Microsoft Excel Driver (*.xls) (32 bit)
FoxPro Files=Microsoft FoxPro Driver (*.dbf) (32 bit)
Text Files=Microsoft Text Driver (*.txt; *.csv) (32 bit)
-->test=SQL Server (32 bit)
[MS Access 97 Database]
Driver32=C:\WINNT\System32\odbcjt32.dll
[dBASE Files]
Driver32=C:\WINNT\System32\odbcjt32.dll
[Excel Files]
Driver32=C:\WINNT\System32\odbcjt32.dll
[FoxPro Files]
Driver32=C:\WINNT\System32\odbcjt32.dll
[Text Files]
Driver32=C:\WINNT\System32\odbcjt32.dll
-->[test]
Driver32=C:\WINNT\System32\sqlsrv32.dll

Hope this helps,
Padma.
0
 

Expert Comment

by:CleanupPing
ID: 9062024
hemanth_ag:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9253878
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[split points between rdov and VPadma]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now