Whats the easiest way to establish a DB connection

Discussion in 'Java' started by Tom, Aug 28, 2003.

  1. Tom

    Tom Guest

    Hello everyone,

    Im looking for the simplest way anyone can thank of to establish a
    connection my my mssql server 2000 through my jdbc. Im looking for a
    bit of code that i can take and build a program ontop of.
    My project for school is to make an address book that will store Name,
    City, phone#, blah blah blah.
    Iv tried on my own but i cant get the connection to go through so i
    thought id start with the connection and build ontop of that.
    If i know the connection works then i dont think ill have any problem
    with the tables and the rest of the code.


    My connection code used to look like this.
    But i kept running into to many errors that i didnt have answers for.
    If anyone has any other suggestions about how to go about doing this i
    would greatly appreciate it.

    private void connect() throws Exception
    {
    JOptionPane.showMessageDialog(null,"CloudScape Inside Connect");

    try
    {
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    Properties p = new Properties();
    p.put("selectMethod","cursor");
    p.put("tom","sa");
    p.put("password","tom");
    connection = DriverManager.getConnection
    ("jdbc:microsoft:sqlserver://TOMLAP2:1433",p);
    }
    catch (Exception ex)
    {
    JOptionPane.showMessageDialog(null, ex.toString());
    }


    try
    {
    connection.setAutoCommit( false );
    }
    catch (Exception ex)
    {
    JOptionPane.showMessageDialog(null, ex.toString());
    }
    }
     
    Tom, Aug 28, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C.W.
    Replies:
    1
    Views:
    5,951
  2. Replies:
    1
    Views:
    514
  3. Varangian

    Establish connection between two users

    Varangian, Jan 4, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    455
    Varangian
    Jan 4, 2006
  4. S J Rulison
    Replies:
    35
    Views:
    3,940
  5. Jim Butler
    Replies:
    7
    Views:
    7,405
    Steven Cheng[MSFT]
    Jul 12, 2006
Loading...

Share This Page