java: How to connect data base without dsn
Hai Guys...
I just want to know about how to connect the java application to MS-ACCESS or oracle without using the DSN (Data Source Name) name.Is there any drivers we need to install otherwise give the code for this.i will expecting for ur correct answers. :thumb:
Re: java: How to connect data base without dsn
Re: java: How to connect data base without dsn
Quote:
Originally Posted by ComputerJy
thanks for your reply..
in your program
cn=DriverManager.getConnection("jdbc:odbc:test","","");
test is the dsn name
i want to connect database without dsn name. please give me correct code..
:thumb:
Re: java: How to connect data base without dsn
Sorry...
This code is created by JBuilder, it uses some pre-compiled borland classes
Code:
public class DataModule1 implements DataModule
{
/**
* Data module reference.
*/
private static DataModule1 myDM ;
private Database database1 = new Database() ;
private QueryDataSet addresses = new QueryDataSet() ;
private QueryDataSet country = new QueryDataSet() ;
/**
* DataModule constructor.
*/
public DataModule1 () {
try {
jbInit() ;
}
catch (Exception exception) {
exception.printStackTrace() ;
}
}
/**
* Initialize.
*
* @throws java.lang.Exception
*/
private void jbInit () throws Exception {
database1.setConnection(new ConnectionDescriptor("jdbc:borland:dslocal:D:\\Borland\\JBuilder2006\\samples\\JDataStore\\datastores\\employee.jds",
"Sample", "", false, "com.borland.datastore.jdbc.DataStoreDriver")) ;
addresses.setQuery(new QueryDescriptor(database1,
"SELECT ADDRESSES.FIRST_NAME,ADDRESSES.LAST_NAME,ADDRESSES.ADDRESS,ADDRESSES.CITY,ADDRESSES.STATE,ADDR" + "ESSES.ZIP FROM ADDRESSES", null, true,
Load.ALL)) ;
country.setQuery(new QueryDescriptor(database1,
"SELECT COUNTRY.COUNTRY,COUNTRY.CURRENCY FROM COUNTRY", null, true,
Load.ALL)) ;
}
/**
* Get data module reference.
*
* @return DataModule reference
*/
public static DataModule1 getDataModule () {
if (myDM == null) {
myDM = new DataModule1() ;
}
return myDM ;
}
public Database getDatabase1 () {
return database1 ;
}
public QueryDataSet getAddresses () {
return addresses ;
}
public QueryDataSet getCountry () {
return country ;
}
}
Re: java: How to connect data base without dsn
Uh, why?
No, it's not possible to connect to anything using JDBC without a DSN. (Unless you use a preconfigured data source, but then the configuration of that source probably used a DSN.) Why would you want to do such a thing?