I need to insert multiple chars into a database table, the code below inserts one random char(in two different ways) in every table row. But i need like 10 different chars in every row. How can i do that?
public static void insertToTable2(Connection c, String tableName, int numberOfRows) throws UnsupportedEncodingException, SQLException {
Random rand = new Random();
String chars = "abcdf";
StringBuilder sql =
new StringBuilder("INSERT INTO " + tableName + " (NR,PIRMAS1,ANTRAS1,TRECIAS1,KETVIRTAS1,PENKTAS1,SESTAS1,SEPTINTAS1,ASTUNTAS1,DEVINTAS1) VALUES ");
for (int j=0; j < numberOfRows; j++)
{
if (j != 0) sql.append (",");
sql.append ("(" + j +
",'" + chars.charAt(rand.nextInt(chars.length())) + "'" +
",'" + chars.charAt(rand.nextInt(chars.length())) + "'" +
",'" + (char)(rand.nextInt(25)+65) + "'" +
",'" + (char)(rand.nextInt()) + "'" +
",'" + (char)(rand.nextInt()) + "'" +
",'" + (char)(rand.nextInt()) + "'" +
",'" + (char)(rand.nextInt()) + "'" +
",'" + (char)(rand.nextInt()) + "'" +
",'" + (char)(rand.nextInt()) + "'" +
")") ;
}
Aucun commentaire:
Enregistrer un commentaire