Thread: new to JDBC
View Single Post
  #6 (permalink)  
Old 05-01-2008, 11:48 AM
DonCash's Avatar
DonCash DonCash is offline
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
What JDK are you using? What editor...?

Use this code. Create a class called connectDS

Code:
import java.sql.*; import com.microsoft.sqlserver.jdbc.*; public class connectDS { public static void main(String[] args) { // Declare the JDBC objects. Connection con = null; try { // Establish the connection. SQLServerDataSource ds = new SQLServerDataSource(); ds.setUser("UserName"); ds.setPassword("*****"); ds.setServerName("localhost"); ds.setPortNumber(1433); ds.setDatabaseName("AdventureWorks"); con = ds.getConnection(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) try { con.close(); } catch(Exception e) {} System.exit(1); } } }
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by DonCash : 05-01-2008 at 12:05 PM.
Reply With Quote