Solved

creating dsn dynamically !

Posted on 2001-06-20
6
700 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 47
use lov values 2 71
ejb message driven bean mdb creation steps 2 34
wild fly 8 startup error 2 37
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

735 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