导入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();
原文:https://www.cnblogs.com/hzb462606/p/9510960.html