Results 1 to 4 of 4
  1. #1
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default Help with Java application to connect to a database

    Hi, I'm trying to write a Java application to connect to a database that resides on our network server. I've been able to connect to the database in question from my client PC using the basic connection code:

    Java Code:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection("jdbcdbc:TEST");
    I created a DSN on my client computer named TEST that mapped a network drive to the database that I wanted to use. All is well! My question is, since there are a fair number of client computers in my network, how can I rig it so that I can connect to the DSN on the server?

    I'd really rather not have to create a DSN on every single client computer, and I'm assuming that there is a way to do this, since it would be really dumb if there wasn't. So if anyone can give me the syntax on how to work this, i'd be delighted. I'm connecting to an access database. One site suggested doing this:

    Java Code:
    Connection conn = DriverManager.getConnection("jdbcdbc:;Driver=Microsoft Access Driver (*.mdb);DBQ=E:/Databases/TestInv.mdb");
    I thought the syntax was a little messy looking but I tried it and it didn't work. Thanks.

  2. #2
    toby is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    There are some extremely talented Java people over at JavaRanch Big Moose Saloon. I'm pretty sure that someone over there will be able to answer about any question that you have.

  3. #3
    herfnai is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Default

    hello you must make odbc and:
    Connection cn=null;
    Statement stm=null;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    cn=DriverManager.getConnection("jdbcdbc:database name");
    stm=cn.createStatement(ResultSet.TYPE_SCROLL_SENSI TIVE,
    ResultSet.CONCUR_UPDATABLE);
    JOptionPane.showMessageDialog(null,"connected");

    }catch(Exception e)
    {JOptionPane.showMessageDialog(null,"eroor" +"\n"+e.getMessage());


    }

  4. #4
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    Can you guys help me connect java to database with driver type 2,3,4.
    I only know connect with type1 JDBC-ODBC Bridge (right?).
    i use SQL SERVER 2005

Similar Threads

  1. connect JDBC to offline database
    By nancyhung in forum JDBC
    Replies: 1
    Last Post: 04-11-2008, 11:04 PM
  2. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:27 AM
  3. Connect Java application to photo editor
    By syellows in forum Advanced Java
    Replies: 1
    Last Post: 11-21-2007, 12:09 AM
  4. Problem to connect Database
    By Swamipsn in forum NetBeans
    Replies: 1
    Last Post: 08-07-2007, 07:13 AM
  5. Replies: 4
    Last Post: 06-05-2007, 01:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •