62,568
社区成员




pstmt=con.prepareStatement("insert into UserLogin values(?,?)");
pstmt.setString(1, "haha4");
pstmt.setString(2, "haha4");
pstmt.addBatch();
pstmt.setString(1, "haha5");
pstmt.setString(2, "haha5");
pstmt.addBatch();
pstmt.setString(1, "haha6");
pstmt.setString(2, "haha6");
pstmt.addBatch();
pstmt.executeBatch();
pstmt.close();
con.close();
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.UUID;
import test.mysql.MConnection;
public class UUIDTest {
public static void test() {
Connection con = null;
PreparedStatement ps = null;
try {
con = MConnection.getConn();
String sql = "insert into uuidtest(uuid) values(?)";
ps = con.prepareStatement(sql);
for (int i = 0; i < 10000; i++) {
String uuid = UUID.randomUUID().toString();
System.out.println(uuid);
ps.setString(1, uuid);
ps.addBatch();
}
ps.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
UUIDTest.test();
}
}