Here you can find the source of ExecuteNoneQuerys(String cmdtext, Object[] parms)
public static int ExecuteNoneQuerys(String cmdtext, Object[] parms) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class Main { public static String mysqlUrl = ""; public static String user = ""; public static String pwd = ""; public static int ExecuteNoneQuerys(String cmdtext, Object[] parms) throws Exception { PreparedStatement pstmt = null; Connection conn = null;//from www . jav a 2 s. c o m try { conn = getConnections(); pstmt = conn.prepareStatement(cmdtext); prepareCommand(pstmt, parms); return pstmt.executeUpdate(); } catch (Exception ex) { System.out.println(ex.getMessage()); throw new Exception("\n error:" + ex.toString()); } finally { if (pstmt != null) { pstmt.clearParameters(); pstmt.close(); } if (conn != null) { conn.close(); } } } public static Connection getConnections() { try { return DriverManager.getConnection(mysqlUrl, user, pwd); } catch (SQLException ex) { return null; } catch (Exception ex) { return null; } } private static void prepareCommand(PreparedStatement pstmt, Object[] parms) throws SQLException, UnsupportedEncodingException { if (parms != null && parms.length > 0) { for (int i = 1; i < parms.length + 1; i++) { Object item = parms[i - 1]; String typeName = item.getClass().getSimpleName(); if (typeName.equals("String")) { pstmt.setString(i, item.toString()); } else if (typeName.equals("Integer")) { pstmt.setInt(i, Integer.parseInt(item.toString())); } else if (typeName.equals("Date")) { pstmt.setDate(i, Date.valueOf(item.toString())); } else { pstmt.setObject(i, item); } } } } }