File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes jdbc problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc problem" Watch "jdbc problem" New topic

jdbc problem

Abed Rabie
Ranch Hand

Joined: Jun 24, 2003
Posts: 74
Dear all,
I face a problem in jdbc.
The problem is : I have a JComboBox that i want to fill it with the database sources that exist in the ODBC DataSources in the administrative tools.
So please inform me how can i write the code that enable me to get all the DataSources from the odbc and filling them into the JcomboBox.
Thx alot for ur help

Abed Rabie
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Abed, no one here will do your work for you. What you will need to do is to at least make an attempt to write the code yourself. Then you can post here with any problems you are having getting it to work.
Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

This might help you:
How to ask questions the right way
And I guess you're a beginner. So errors are accepted. But don't email questions like this one again. The next time you aren't a beginner anymore.
Instead of begging for pardon, read the article.
You're welcome.
Abed Rabie
Ranch Hand

Joined: Jun 24, 2003
Posts: 74
Dear all,
I'm not like you to tell me the code i'm just want to know the start point of the road.
I mean the classes that may help me doing this task.
Thx for help
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

Allow me to suggest the following "starting points":
  • "How to Use Combo Boxes" lesson in the Java Tutorial
  • "JDBC(TM) Database Access" trail of the Java Tutorial

  • Good Luck,
    Abed Rabie
    Ranch Hand

    Joined: Jun 24, 2003
    Posts: 74
    Dear All,

    Once i need to connect to any database we write down the following:

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" );
    Connection con=DriverManager.getConnection("jdbc dbc:myDatabaseName","sa","");

    Statement stat=con.createStatement();

    // then we make the query statement here

    what i need is not to connect to certain database in my System DSN but i need to get all the database names from within my system DSN.

    I think to use the URL class. But i don't get any acurate vision.

    If you can't help me tell me cause i don't like to disturbe you any more.

    Best reagrds

    Blake Minghelli
    Ranch Hand

    Joined: Sep 13, 2002
    Posts: 331
    I don't think the other posters understood what you are asking for. Abed is not asking for help on "how to use JComboBox" or "how to use JDBC", rather he is asking this:
    How do you find all of the ODBC data sources that are configured on a Windows PC?

    It sounds like Abed wants to be able to get a list of DSN's from the PC and display them in a combobox so the user can pick one. But how do you get that list using Java?

    I don't know the answer but I thought it might help if I re-worded your question. Since this is specific to Windows, you may have to use a native library to get that info.

    Abed just needs a starting point, e.g. "check out this API XXX" or "there is a tool called XXX that can help you". Anyone have any experience with this?

    Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
    Jeanne Boyarsky
    author & internet detective

    Joined: May 26, 2003
    Posts: 33119

    I don't know of any way to get a list of databases on a machine. It's possible to list all the tables in a database, but I don't think you can list the databases on a machine.

    What are you trying to do with this information? Maybe there is another way to accomplish it.

    [OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
    Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
    Abed Rabie
    Ranch Hand

    Joined: Jun 24, 2003
    Posts: 74
    Dear all,

    I find a solution but it's not so good from my point of view. I get all the database names that exist on the sql server path and listed them in my combobox but this is a bad way cause if anyone change this path, i will not be able to get any DSN.

    waitting for your reply

    best regards

    I agree. Here's the link:
    subject: jdbc problem
    It's not a secret anymore!