• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic DSN creation

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I want to Dynamically generate the DSN for database connectivity, so that i do not need to go to ODBC and create DSN for the database.
Is there any way by which we can create the DSN for a particular database in our code itself and then use it for querrying.

Thanks!
Abhinav
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The DSN for a Windows ODBC connection is held in the registry. You can export a specific DSN into a .reg file which you can then reload into the registry.

It's possible that you could use a variation of that technique to create the DSN. Of course your code would have to have permission to run on each relevant machine.

Another alternative may be to use an API to register the DSN in the registry.

Hope this helps.

Jules
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,

You can use system dsn,so that any user of the system can use it.Else,create file dsn and you are not needed to create every time,just set the location of the file dsn.

Dsn file basically contains the location of the driver name,location,datasource name,username etc.

If you do not want dsn to be used,go for type 2 or type 4 Driver.There will be no need to craete dsn.

Here is the sample for them

Type 2 - The Oracle OCI JDBC driver requires an installation of Oracle's SQL*Net to provide communication to the database server.

Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc : oracle : oci8 : @hostname : Databasename", "scott", "tiger");

Type 4 - 100% Java Driver
mainly used for webappl.Fast access.Nothing is needed preinstalled.
Oracle provides thin driver for this.

Driver driver = (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
DriverManager.registerDriver(driver);
conn = DriverManager.getConnection("jdbc : oracle : thin : @127.0.0.1:1521 bname", "scott", "tiger")


[ August 05, 2004: Message edited by: Mohd Afroz Ahmed ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic