赞
踩
文档中是这样写的void setString(int parameterIndex,String x)
conn = DriverManager.getConnection(url, userName, password);//自己链接数据库
PreparedStatement pstmtInsert = conn.prepareStatement("INSERT INTO student VALUES(?, ?,
?, ?)"); // 创建语句,里面的参数等可以用问号代替pstmtInsert.setString(1,"a");//给第一个
问号赋值"a";pstmtInsert.setString(2,"b");//给第二个问号赋值"b";...................
- public synchronized void insert(String sql, LinkedHashMap<String, String> data, String startFileName) {
- Connection conM = getConnection();
- Map<String, Object> map = null;
- PreparedStatement pst = null;
- try {
- pst = conM.prepareStatement(sql);
- Iterator<String> kits = data.keySet().iterator();
- int fi = 0;
- while (kits.hasNext()) {
- fi++;
- String f = kits.next();
- pst.setString(fi, data.get(f));
- }
- LogsUtil.log(startFileName + "_sql.sql", "" + pst.toString().substring(pst.toString().indexOf(":") + 1) + ";", "utf8");
- // pst.execute();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (pst != null) {
- pst.close();
- pst = null;
- }
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。