import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class test {
/*
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jihedb";
String user = "sa";
String password = "517747";
Connection conn = null;
PreparedStatement pstmt=null;
ResultSet rs = null;
public test() {
try {
Class.forName(sDBDriver);
} catch (java.lang.ClassNotFoundException e)
{
System.err.println("DBconn(): " + e.getMessage());
}
}
*/
String url="jdbc:jtds:sqlserver://localhost:1433/jihedb";
String username="sa";
String password="517747";
static Connection conn=null;
PreparedStatement pstmt=null;
//构造函数
public test()
{
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
conn=DriverManager.getConnection(url,username,password);
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}catch(SQLException e)
{
e.printStackTrace();
}
}
//main()函数
public static void main(String args[]) throws SQLException{
test m=new test();
PreparedStatement ps =conn.prepareStatement( "INSERT into code values (?,?)");
Date t=(Calendar.getInstance()).getTime();
Set s=new HashSet();
Date tt=(Calendar.getInstance()).getTime();
System.out.print("插入开始"+tt);
int count=0;
//LinkedList v=new LinkedList();
ArrayList v=new ArrayList();
for(int i=1;i<1000000;i++){
v.add(i);
}
System.out.println("长度"+v.size());
Iterator vv=v.iterator();
while(vv.hasNext()){
ps.setObject(1,vv.next());
ps.setString(2, "0");
ps.addBatch();
count+=1;
if(count%1000==0)
{
ps.executeBatch();
}
}
ps.executeBatch();
Date ttt=(Calendar.getInstance()).getTime();
System.out.print("结束"+ttt);
}
}