package mysqlconnect;
import java.sql.*;
class Insert{
public static void main(String args[]) throws SQLException, ClassNotFoundException{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://db4fre.net/sumit1234","sumit1234","sumit1234");
//here db4fre.net/sumit1234 is server/database name, sumit1234 username and sumit1234password
Statement stmt=con.createStatement();
String begin = "INSERT INTO `test`(`firstname`, `lastname`) VALUES ";
for (int i = 2000; i < 3001; i++) {
begin = begin + "(" + i + "," + (i + 10) + ")" + ",";
}
begin = begin.replaceAll(",$", ";"); //As we want ; after last value
stmt.executeUpdate(begin); //INSERT DELTE UPDATE needs executeUpdate
con.close();
}
}
import java.sql.*;
class Insert{
public static void main(String args[]) throws SQLException, ClassNotFoundException{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://db4fre.net/sumit1234","sumit1234","sumit1234");
//here db4fre.net/sumit1234 is server/database name, sumit1234 username and sumit1234password
Statement stmt=con.createStatement();
String begin = "INSERT INTO `test`(`firstname`, `lastname`) VALUES ";
for (int i = 2000; i < 3001; i++) {
begin = begin + "(" + i + "," + (i + 10) + ")" + ",";
}
begin = begin.replaceAll(",$", ";"); //As we want ; after last value
stmt.executeUpdate(begin); //INSERT DELTE UPDATE needs executeUpdate
con.close();
}
}
No comments:
Post a Comment