![]() ![]() ![]() To connect to the default instance on a remote server, use the following example: String url = "jdbc:sqlserver://MyServer encrypt=true integratedSecurity=true " Each approach depends on the properties that you set by using the connection URL. If you have to make a database connection that targets a specific data source, there are a number of approaches that you can take. If you have to create a connection by using the SQLServerDataSource class, you can use various setter methods of the class before you call the getConnection method, as in the following: SQLServerDataSource ds = new SQLServerDataSource() Ĭreating a connection that targets a specific data source String connectionUrl = "jdbc:sqlserver://localhost encrypt=true database=AdventureWorks integratedSecurity=true "Ĭonnection con = d.connect(connectionUrl, new Properties()) Ĭreating a connection by using the SQLServerDataSource class If you have to specify a particular driver in the list of drivers for DriverManager, you can create a database connection by using the connect method of the SQLServerDriver class, as in the following: Driver d = (Driver) Class.forName(".SQLServerDriver").newInstance() Creating a connection by using the SQLServerDriver class For more information, see Using the JDBC Driver. When the getConnection method of the DriverManager class is called, an appropriate driver is located from the set of registered JDBC drivers. When using the sqljdbc4.jar class library, applications do not need to explicitly register or load the driver by using the Class.forName method. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |