1.Java.io.ByteArrayOutputStream.writeTo()方法实例
java.io.ByteArrayOutputStream.writeTo(OutputStream out) 方法写入该字节数组输出流的内容到指定的输出流参数。
2.xiecheng的数据库都是用的Mysql,不用Oracle。不用SQLServer,因为SQLServer有漏洞,不安全。
3.数据库等连接必须关闭。
参考:
package com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class TestPreparedStatement {
public static void main(String[] args) {
Connection con = null;
PreparedStatement pst = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=userManager";
con = DriverManager.getConnection(url, "as", "");
String sql = "insert into myuser (userName,pwd) values (? , ?)";
pst = con.prepareStatement(sql);
pst.setString(1, "张三"); //也可以用setObject()
pst.setString(2, "123");
pst.addBatch();
pst.setString(1, "李四");
pst.setString(2, "456");
pst.addBatch();
pst.executeBatch();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (pst != null) {
pst.close();
pst = null;
}
if (con != null) {
con.close();
con = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
参考:http://blog.sina.com.cn/s/blog_6fd9615d01010e2h.html
4.
5.