JAVA preparedStatement.executeBatch
אני נתקל בבעיה עם הפונקציה הזו ואשמח לעזרה.
נראה לי שאני עושה משהו בסיסי לא נכון.
אני מנסה להכניס כמה עשרות רשומות. אני לא מקבל שום חריגות או הודעות שגיאה בפונצקיה, אבל ב-DB לא רואים שום שורה שהוכנסה.
לא נראה לי שזה עניין של הרשאות או חסר commit, כי כשניסיתי את אותו תהליך לא ב-batch, זה עובד ואני רואה את הרשומות ב-DB.
אגב, גם ניסיתי לבדוק את הקוד שמחזירה הפונקציה (היא מחזירה מערך של מספרים) ובכולם הערך 1 , שלפי מה שהבנתי זה אומר שהפעולה הצליחה.
/*
* should create the league in DB at the start of the season
*
* UNDER DEVELOPMENT
*/
public void createLeagus()
{
String sqlSelect= "SELECT team_num, place " +
"FROM clubs_information " +
"WHERE current_league = 1 " +
"ORDER BY place";
String sqlInsert= "INSERT INTO seasons_tables " +
"(year, team_num, round, w_group, wins, losts, draw, positive, negative, points) VALUES " +
"("+Season.getYear()+", ?, 1, ?, 0, 0, 0, 0, 0, 0)";
System.out.println(sqlInsert);
try
{
resultSet=statement.executeQuery(sqlSelect);
PreparedStatement preparedStatement=connection.prepareStatement(sqlInsert);
while(resultSet.next())
{
int place=resultSet.getInt("place");
int group=0;
int teamNum=resultSet.getInt("team_num");
if(place%10 == 1 || place%10 == 0)
group=1;
if(place%10 == 2 || place%10 == 9)
group=2;
if(place%10 == 3 || place%10 == 8)
group=3;
if(place%10 == 4 || place%10 == 7)
group=4;
if(place%10 == 5 || place%10 == 6)
group=5;
preparedStatement.setInt(1, teamNum);
preparedStatement.setInt(2, group);
preparedStatement.addBatch();
System.out.println("INSERT NUM: " + teamNum + "TO GROUP : " + group );
}
preparedStatement.executeBatch();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
אני נתקל בבעיה עם הפונקציה הזו ואשמח לעזרה.
נראה לי שאני עושה משהו בסיסי לא נכון.
אני מנסה להכניס כמה עשרות רשומות. אני לא מקבל שום חריגות או הודעות שגיאה בפונצקיה, אבל ב-DB לא רואים שום שורה שהוכנסה.
לא נראה לי שזה עניין של הרשאות או חסר commit, כי כשניסיתי את אותו תהליך לא ב-batch, זה עובד ואני רואה את הרשומות ב-DB.
אגב, גם ניסיתי לבדוק את הקוד שמחזירה הפונקציה (היא מחזירה מערך של מספרים) ובכולם הערך 1 , שלפי מה שהבנתי זה אומר שהפעולה הצליחה.
/*
* should create the league in DB at the start of the season
*
* UNDER DEVELOPMENT
*/
public void createLeagus()
{
String sqlSelect= "SELECT team_num, place " +
"FROM clubs_information " +
"WHERE current_league = 1 " +
"ORDER BY place";
String sqlInsert= "INSERT INTO seasons_tables " +
"(year, team_num, round, w_group, wins, losts, draw, positive, negative, points) VALUES " +
"("+Season.getYear()+", ?, 1, ?, 0, 0, 0, 0, 0, 0)";
System.out.println(sqlInsert);
try
{
resultSet=statement.executeQuery(sqlSelect);
PreparedStatement preparedStatement=connection.prepareStatement(sqlInsert);
while(resultSet.next())
{
int place=resultSet.getInt("place");
int group=0;
int teamNum=resultSet.getInt("team_num");
if(place%10 == 1 || place%10 == 0)
group=1;
if(place%10 == 2 || place%10 == 9)
group=2;
if(place%10 == 3 || place%10 == 8)
group=3;
if(place%10 == 4 || place%10 == 7)
group=4;
if(place%10 == 5 || place%10 == 6)
group=5;
preparedStatement.setInt(1, teamNum);
preparedStatement.setInt(2, group);
preparedStatement.addBatch();
System.out.println("INSERT NUM: " + teamNum + "TO GROUP : " + group );
}
preparedStatement.executeBatch();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}