Java examples for java.sql:SqlServer
get Connection to Sql Server
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main{ public static void main(String[] argv) throws Exception{ System.out.println(getConnection()); }/*from www . ja v a2 s. c o m*/ private static final String URL_DATABASE = "jdbc:sqlserver://localhost:1433;databaseName=master;"; private static final String USUARIO_DB = "sa"; private static final String SENHA_USUARIO_DB = "123"; public static Connection getConnection() throws exception { try { Connection connection = DriverManager.getConnection( URL_DATABASE, USUARIO_DB, SENHA_USUARIO_DB); connection.setAutoCommit(true); return connection; } catch (SQLException e) { throw new exception(e); } } }