A recent need to verify the "Android Terminal" Download data efficiency issues, which need to add test data to the SQLSERVER2008 database
Step1: Defining related Database Information
Static final String DRIVER = "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; static final String URL = "jdbc:sqlserver:// 192.168.0.249\\sql2008;databasename=lzrfid "; static final string USER =" sa "; static final String PWD =" 1 ";
Step2: Getting SQL connections
/** * * Get SQL Connection * @return * @author * @since 1.0.0 */public static Connection getconnection () {Connection con = nu ll;try {class.forname (DRIVER); con = drivermanager.getconnection (URL, user,pwd);} catch (ClassNotFoundException e) { E.printstacktrace ();} catch (SQLException e) {e.printstacktrace ();} return con;}
Step3: A simple operational database
Statement Statement; Connection Connection; Connection = getconnection (); statement = Connection.createstatement ();
String sql = "SELECT * From ...";
Statement.execute (SQL);
The above is just the simplest connection operation, here to save, easy to consult later
Java Connection SQL Server code snippet