標籤:prepare state lda soft date rest jar com getc
匯入jar包:sqljdbc4-2.0.jar
網盤:https://pan.baidu.com/s/1vVK6Q3Qv53GFBPsP4hl6EQ
載入驅動:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
建立url:
url = "jdbc:sqlserver://{IP};DatabaseName={DbName}";
其他的都跟串連MySQL一樣,以下為執行個體:
//載入驅動 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); url = "jdbc:sqlserver://" + SsqlBean.getSQLIP() + ";DatabaseName=" + SsqlBean.getSQLDataBase();
//建立資料庫連接對象 Connection conn = DriverManager.getConnection(url, SsqlBean.getSQLUserName(), SsqlBean.getSQLPassword()); String sql="insert into SKUbus(WarehouseCode,ClientCode,ClientRefNo,SKUNo) " + "values(?,?,?,?)";
//建立先行編譯的資料庫操作對象:PreparedStatement PreparedStatement pre=conn.prepareStatement(sql); pre.setQueryTimeout(60); //WarehouseCode pre.setString(1, listBean.get(i).getStr_warehouseCode()); //ClientCode pre.setString(2, ClientCode[j]); //ClientRefNo pre.setString(3, listBean.get(i).getStr_RefNoDate()); //SKUNo pre.setString(4, listBean.get(i).getStr_itemCode()); //執行 pre.executeUpdate();
Java串連SQL server