1.Java.io.ByteArrayOutputStream.writeTo()方法實例html
java.io.ByteArrayOutputStream.writeTo(OutputStream out) 方法寫入該字節數組輸出流的內容到指定的輸出流參數。java
2.xiecheng的數據庫都是用的Mysql,不用Oracle。不用SQLServer,由於SQLServer有漏洞,不安全。sql
3.數據庫等鏈接必須關閉。數據庫
參考:數組
package com;安全
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;sqlserver
public class TestPreparedStatement {
public static void main(String[] args) {
Connection con = null;
PreparedStatement pst = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");url
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=userManager";
con = DriverManager.getConnection(url, "as", "");
spa
String sql = "insert into myuser (userName,pwd) values (? , ?)";
pst = con.prepareStatement(sql);
server
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.