Results 1 to 3 of 3

Thread: Java Connecting to MS SQL Server

  1. #1
    Join Date
    Apr 2005
    Posts
    9
    Rep Power
    0

    Exclamation Java Connecting to MS SQL Server

    Help needed in Database Connection
    Has any one ever used java ODBC to connect toe MS SQL Server JDBC Driver??
    Is the any code I could use or some tips to hlp me doing the connection.

  2. #2
    Join Date
    Jun 2003
    Posts
    453
    Rep Power
    0

    Default

    Regardless of whether you're trying to connect to Oracle, Sybase, Informix, mSQL, or Interbase (or any other JDBC data source), establishing a connection to an SQL database with Java JDBC is a simple two-step process:

    1. Load the JDBC driver.
    2. Establish the connection.
    More information may be gathered from here .

    Code:
          //  Establish a connection to a mSQL database using JDBC. 
    
          import java.sql.*; 
    
          class JdbcTest1 { 
               
              public static void main (String[] args) { 
                  try { 
    
                      // Step 1: Load the JDBC driver. 
                      Class.forName("com.imaginary.sql.msql.MsqlDriver"); 
    
                      // Step 2: Establish the connection to the database. 
                      String url = "jdbc:msql://www.myserver.com:1114/contact_mgr"; 
                      Connection conn = DriverManager.getConnection(url,"user1","password");  
    
                  } catch (Exception e) { 
                      System.err.println("Got an exception! "); 
                      System.err.println(e.getMessage()); 
                  } 
              } 
          }
    We Is Friends!
    Me And You Is Friends!
    You Smile, I Smile ....
    You Hurt, I Hurt ..
    You Cry, I Cry ..
    You Jump Off A Bridge ..
    I Gonna Miss Your E-Mails !

  3. #3
    Join Date
    Aug 2004
    Posts
    34
    Rep Power
    0

    Default

    Quote Originally Posted by Jancooperation
    Help needed in Database Connection
    Has any one ever used java ODBC to connect toe MS SQL Server JDBC Driver??
    Is the any code I could use or some tips to hlp me doing the connection.
    You need to download and use the JTDS JDBC driver library. This is the same JDBC library that is used to connect to Sybase.

Posting Permissions

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