import java.sql.*;public class Insert extends Thread {
public Connection getConnection() {
String url = "jdbc:oracle:thin:@localhost:1521:ora9i";
String user = "scott";
String password = "tiger";
Connection con = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
e.printStackTrace();
}
return con;
} public void run() {
long a = 13819100000L;
long b = 13819101000L;
Connection con = null;
Insert insert = new Insert();
try {
con = insert.getConnection();

synchronized (this) {
for (long c = a; c <= b; c++) {
Statement stmt = null;
stmt = con.createStatement();
String sql = "insert into telepnum values(" + c + ")";

stmt.executeUpdate(sql);
if (stmt != null) {
stmt.close();
}
System.out.println(c);
} sleep(10);
}
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
}
} public static void main(String[] args) {
Insert insert = new Insert();
new Thread(insert).start();//多线程插数据
new Thread(insert).start();
new Thread(insert).start(); }
}代码如上,我想要用多线程插数据,但是这样的问题是,创建3个线程,结果同样的数据插了3遍……