Hi
I am having major problems with my sql statements. I have set up a fantasy football application which users have to pick 10 teams.I have a table in my database called "teams" which contains account ID(aid) and team number(tno). When a user selects a team I want the statement to get the name of the team,check the team number for that team and then insert this team number in a table called "jtable" which contains "aid" and "tno".I have set implemented some code in my jsp page but this will only enter in the first team that is selected and will ignore the the rest of the selections. I would be very grateful if anyone could tell me what is being done wrong.
<% //load the MySQL JDBC Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
//open a connection to the "fantasyfootball" database
Connection con = DriverManager.getConnection("jdbcdbc:fantasyfootball2","",""
//create a statement object for sending SQL queries
Statement stmt = con.createStatement();
Statement stmt1 = con.createStatement();
ResultSet res2=stmt.executeQuery("SELECT tno from teams where name ='"+request.getParameter("prem_choices_1"+"'"
while(res2.next()){
int team_no=res2.getInt("tno"
res2.close();
stmt.executeQuery("INSERT INTO jtable(aid,tno)VALUES('1','"+team_no+"')"
res2.next();
}
ResultSet res3=stmt.executeQuery("SELECT tno from teams where name ='"+request.getParameter("prem_choices_2"+"'"
while(res3.next()){
int team_no=res2.getInt("tno"
res3.close();
stmt.executeQuery("INSERT INTO jtable(aid,tno)VALUES('1','"+team_no+"')"
res3.next();
}
//clean up
stmt.close();
con.close(); %>
Thanks
Patrick
I am having major problems with my sql statements. I have set up a fantasy football application which users have to pick 10 teams.I have a table in my database called "teams" which contains account ID(aid) and team number(tno). When a user selects a team I want the statement to get the name of the team,check the team number for that team and then insert this team number in a table called "jtable" which contains "aid" and "tno".I have set implemented some code in my jsp page but this will only enter in the first team that is selected and will ignore the the rest of the selections. I would be very grateful if anyone could tell me what is being done wrong.
<% //load the MySQL JDBC Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
//open a connection to the "fantasyfootball" database
Connection con = DriverManager.getConnection("jdbcdbc:fantasyfootball2","",""
//create a statement object for sending SQL queries
Statement stmt = con.createStatement();
Statement stmt1 = con.createStatement();
ResultSet res2=stmt.executeQuery("SELECT tno from teams where name ='"+request.getParameter("prem_choices_1"+"'"
while(res2.next()){
int team_no=res2.getInt("tno"
res2.close();
stmt.executeQuery("INSERT INTO jtable(aid,tno)VALUES('1','"+team_no+"')"
res2.next();
}
ResultSet res3=stmt.executeQuery("SELECT tno from teams where name ='"+request.getParameter("prem_choices_2"+"'"
while(res3.next()){
int team_no=res2.getInt("tno"
res3.close();
stmt.executeQuery("INSERT INTO jtable(aid,tno)VALUES('1','"+team_no+"')"
res3.next();
}
//clean up
stmt.close();
con.close(); %>
Thanks
Patrick