Here you can find the source of ExecuteUpdate(String sql, List
public static int ExecuteUpdate(String sql, List<String> paras)
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; public class Main { private static String dbConnectionStr = "jdbc:sqlserver://127.0.0.1:1433;databasename=cyyz"; private static String sUser = "sa"; private static String sPassWord = "Ss123"; private static String dbDriverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; private static Connection dbConnection; public static int ExecuteUpdate(String sql, List<String> paras) { int iRet = 0; try {/*from w ww . j a v a2 s. c om*/ GetConnection(); PreparedStatement stm = dbConnection.prepareStatement(sql); if (stm != null) { for (int i = 0; i < paras.size(); i++) { stm.setString(i + 1, paras.get(0)); } iRet = stm.executeUpdate(sql); } } catch (Exception e) { e.printStackTrace(); } finally { EndConnection(); } return iRet; } private static void GetConnection() throws Exception { if (dbConnection == null) { Class.forName(dbDriverName); dbConnection = DriverManager.getConnection(dbConnectionStr, sUser, sPassWord); } } private static void EndConnection() { if (dbConnection != null) { try { dbConnection.close(); } catch (SQLException e) { e.printStackTrace(); } finally { dbConnection = null; } } } }