HOW TO CREATE DSN DYNAMICALLY?

Hello viewers,

I want to transfer the data from Excel file to oracle database ,for that purpose iam using

EXCEL DRIVER, but it requires DSN for each work book.

Myclient is unaware of creating the dsn.How can

create the dsn dynamically.

please solve this problem.

Bye

Ramesh

[346 byte] By [rameshchanamolu] at [2007-9-26 1:29:16]
# 1
db = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=c:/temp/myworkbook.xls;DriverID=22;READONLY=false","","");
Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Hi,I found your post to be interesting. Can anyone tell me how to create a DSN for MSAccess dynamically
abhimanyu31 at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
db = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:/data/Access/test1.mdb","dba","sql");Look out: 1 blank before (*.mdb) !!!
Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Oh,

I had no idea you could use the URL in that fashion, too. Can you recommend some documentation on it (preferably online ;)? Also, I've played around a little with the Statement objects you can create from this, but didn't get any Standard-SQL things to work. Do you know any docs on that, too?

RBerle at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

Sorry, I know no more docs about this.

But I'm sure, that afterwards you have a valid ODBC connection (as if you had done it about a system DSN), so it should be able to do everything what your ODBC can do.

So for example with SQLServer I can't use scrollable ResultSets, by both ways.

Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> [code]db = DriverManager.getConnection(

> "jdbc:odbc:Driver={MicroSoft Access Driver

> (*.mdb)};DBQ=D:/data/Access/test1.mdb","dba","sql");[/c

> de]Look out: 1 blank before (*.mdb) !!!

How can I enforce username/password? At the moment, I can create DSN dynamically disregarding what username/password I specified.

Can U help?

nstafe at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

> How can I enforce username/password? At the moment, I can create DSN dynamically disregarding what username/password I specified.

"Create DSN dynamically" is nothing else than connect to a DB.

Now, JDBC-ODBC with fix or dynamically defined DSN btw. every JDBC driver passes user and password to the DB, when you try to do the connect.

If and what user and password you need is completely the definition of the DB only.

I don't know Access much, but I think, it's possible to protect an Access DB this way. Look at the Access docs.

Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

> db = DriverManager.getConnection(

> "jdbc:odbc:Driver={MicroSoft Access Driver

> (*.mdb)};DBQ=D:/data/Access/test1.mdb","dba","sql");

Hartmut hi,

If I try your code from above I get an SQL-Exception:

Data-sourcename is too long

I admit, my access-file was in a directory with 5 super-directory but even something like c:/Db.mdb gave the same error. Any idea?

I am using XP if that matters.

thanks,

TheStijn

TheStijn at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9

This message means nothing more than that's any mistake in your connect string.

Look if you have taken care for each blank! They're importent.

If you can't find it: Post your connect command, exactly, each character.

You'd be the first one who didn't get it.

But:

it seems to be necessary to have JDK 1.3 at least.

Do you have?

Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10
hi,that will probably be it. I'm using Visual Age to develop and that uses 1.2.2. I just added the exact line of code I used anyway, but I suppose it's correct.Thanks for your help,TheStijn
TheStijn at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11
oops, forgot the line:c = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Work/Projects/Financien/Testing.mdb");
TheStijn at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 12
Your post exactly doesn't show the critical position:between "Driver" and "(*.mdb)" there must be a blank.
Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 13
hi,I checked, there is a blank.
TheStijn at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 14
Then it seems to be true that you need at least JDK 1.3
Hartmut at 2007-6-29 1:25:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 15

I think you need the MS Access driver version 4.xx.... and up. I have not gotten it to work with version 3.5 yet.

How to check:

to check your driver version:

click Start->

Settings->

Control Panel->

ODBC Data Sources (32bit)->

Drivers tab->

Should display Microsoft Access Driver(*.mdb) - version x.xx.xxxx.xx

Jamie

jlrober at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 16
I checked, I am using version 4006... something.Hartmut will probably be right about the jdk version.Tx anyway,Stijn
TheStijn at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 17

Great thread but let's kick it up a notch! can you create a dyanmic DSN using a http file rather than just a file?

i.e

Connection con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=http://remotemachine/my_data.mdb","dba","sql");

Note

I'm runninga webserver and my_data.mdb is on the root of remotemachine.

SBattista at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 18
hai all,i found a very nice discussion in this. but i want to create dsn dynamically for "Oracle ODBC Driver" using java. how to. can anybody help me in this. its very urgent. i project got strucked because of this topic. please help me.bybvrk.
bvrkii at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 19
Will this also work to connect to the ms access db through a java prg. both residing in the unix environment.
rajeev_ckp at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 20

> hai all,

> i found a very nice discussion in this. but i

> t i want to create dsn dynamically for "Oracle ODBC

> Driver" using java. how to. can anybody help me in

> this. its very urgent. i project got strucked

> because of this topic. please help me.

> by

> bvrk.

Why on earth would you want to do this when you can already make a DSN-less connection to Oracle using their thin JDBC driver?

The ONLY reason to worry about this topic is if you have no alternative besides an ODBC driver. If you've got a JDBC driver, use it. JMO - MOD

duffymo at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 21

Hello,

How do I connect to a DBF(dBase) file in the same way as the Access file?

I do something like this and it didn't work:

db = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft dBase Driver (*.dbf)};DBQ=C:/myData.dbf");

I got this error:

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC dBase Driver]

'(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

Can anyone help?

-Hoang

htruong@mitre.org at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 22
> How do I connect to a DBF(dBase) file in the same way> as the Access file?String url = "jdbc:odbc:Driver={Microsoft dBase Driver (*.dbf)};DBQ=C:\\myData.dbf"; Also check if the path is correct and don't resurrect old threads.
rich_the_leo at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 23
II solved the problem. We can't have the filename (myData.dbf) - just have the location where dbf file/files located (C:\\)String url = "jdbc:odbc:Driver={Microsoft dBase Driver (*.dbf)};DBQ=C:\\"
htruong@mitre.org at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 24

i tried this ,the path of the .mdb file if it is an absolute path then this works or else it does nt work..

i mean to say it works only if an absolute path of the.mdb file is given.it doesnt work on relative path...if anybody has made it work on relative path.pls post that code so that we can learn

sahitya at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 25
Why waste your time waiting for that? Just use a java.io.File object to convert the relative path to the absolute path, then use the absolute path.
DrClap at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 26

actually i found this on internet :

using servlet context context= new ServletCOntext();

then String art= context.getRealpath("/");

this art gives the absolute path of the the servlet using this.By appending or truncating the path we will be able to get to the .mdb file.

This works ,i dont think is a proper way.

I want to know if we have any way of working with relative path using .mdb? i am inquisitive about knowing any such way?

Mr.DrClap. thanks for answering my question.i checked it out ,there is a method call get absolute path .it looks pretty coool way handling but still dont have that clarity .can u elaborate on that .do u use this get absolute path of servlet or the .mdbfile..

sahitya at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 27

What's to elaborate? If you have a relative path, make a File object from it. (File has a constructor that takes a String.) Then call that File object's getAbsolutePath method and you've got the absolute path. Most likely the answer is clear but you don't really understand the question. Your fault for hijacking the thread.

DrClap at 2007-6-30 21:57:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...