Import jar Package: Sqljdbc4-2.0.jar
NET Disk: Https://pan.baidu.com/s/1vVK6Q3Qv53GFBPsP4hl6EQ
Load driver:
Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
To create a URL:
url = "Jdbc:sqlserver://{ip};D Atabasename={dbname}";
The rest is the same as the connection to MySQL, the following is an example:
//Load DriverClass.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver"); URL= "jdbc:sqlserver://" + ssqlbean.getsqlip () + ";D atabasename=" +ssqlbean.getsqldatabase ();
Create a database Connection object Connection Conn=drivermanager.getconnection (URL, ssqlbean.getsqlusername (), Ssqlbean.getsqlpassword ()); String SQL= "INSERT into Skubus (Warehousecode,clientcode,clientrefno,skuno)" + "VALUES (?,?,?,?)";
To create a precompiled database Operation object: PreparedStatement preparedstatement pre=conn.preparestatement (SQL); Pre.setquerytimeout (60); //WarehousecodePre.setstring (1, Listbean.get (i). Getstr_warehousecode ()); //ClientcodePre.setstring (2, Clientcode[j]); //ClientrefnoPre.setstring (3, Listbean.get (i). Getstr_refnodate ()); //SkunoPre.setstring (4, Listbean.get (i). Getstr_itemcode ()); //ExecutePre.executeupdate ();
Java Connection SQL Server