?
Solved

DSN-Less JDBC connections

Posted on 2002-03-12
8
Medium Priority
?
316 Views
Last Modified: 2013-11-23
I have 2 SQL Server 2000 Databases. One is the master database of user accounts . In one of the tables in that database is a field that contains a connection string that points to the users database which could be anywhere on any type of database.

How do I create connection objects in Java Using JDBC without using a dsn.
0
Comment
Question by:cvcarson
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:onebadboy
ID: 6858707
You need a Type 4 driver ( A Jdbc Driver specifically for the database you are trying to connect to)


click the following link:
http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml
If that doesn't work go to Microsoft's home page and type this in the search box: Microsoft SQL Server 2000 Driver for JDBC

Download and install. It comes with instructions on how to create the connection string. This needs to be on any machine that the applet/application/or servlet will be running on.

Quick Side note. It seems to me that you are going to have to do a little bit of planning because this driver will only work with MS SQL Server not Oracle not MySQL just MS SQL Server. So you're going to need a field in your db table saying what kind of db the connect string is for.


Hope this helps

0
 

Author Comment

by:cvcarson
ID: 6858718
This project was originally for c++ server side code and I was using ADO. But my inexperience with pointers made me migrate to Java (I like much better by the way).

It's no problem adding a field to the db. All of our customers have are on our SQL Server 2000 Db's I was just thinking about the future but for now this will work.

I will test and award points if it works.

Thanks
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6859128
I only tried Oracle thin connection...so far
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 1

Expert Comment

by:skinsella
ID: 6860295
If you don't want to go down the Type 4 route, you could  use the ODBC JDBC Bridge assuming there is a SQL Server ODBC Driver locally (there should be).

Anyway, here's an example for MS-Access, you just need to amend the connection string and driver name for SQL Server.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String db = "jdbc:odbc:Driver={Microsoft Access(*.mdb)};DBQ=C:/foo/foobar.MDB";

Connection DBConn = DriverManager.getConnection(db,"","");

You will have to replace the [Microsoft Access *.mdb] part with the ODBC driver name exactly as it appears in the Driver column of the ODBC DataSource Configuration on your windows machine.

If this is unclear, please repost...

Regards,

Sean
0
 

Author Comment

by:cvcarson
ID: 6860972
I like this idea. But can you give me an example of SQL Server?
0
 
LVL 1

Accepted Solution

by:
skinsella earned 800 total points
ID: 6861049
Just done this and it works (2 differnet ways):

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String connectionString = "jdbc:odbc:Driver={SQL Server};Server=100.99.1.2;Database=MyDatabase;Uid=username;Pwd=password;";

Connection DBConn = DriverManager.getConnection(connectionString);

OR

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String connectionString = "jdbc:odbc:Driver={SQL Server};Server=100.99.1.2;Database=MyDatabase;";

Connection DBConn = DriverManager.getConnection(connectionString, "username", "password");
0
 

Author Comment

by:cvcarson
ID: 6861081
I will try it.
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6863146
If you face a problem, try this:

Class myClass = Class.forName(....)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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