Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert statement

Status
Not open for further replies.

gearypa

Programmer
Apr 14, 2003
4
IE
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(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);



//open a connection to the &quot;fantasyfootball&quot; database
Connection con = DriverManager.getConnection(&quot;jdbc:eek:dbc:fantasyfootball2&quot;,&quot;&quot;,&quot;&quot;);

//create a statement object for sending SQL queries
Statement stmt = con.createStatement();
Statement stmt1 = con.createStatement();


ResultSet res2=stmt.executeQuery(&quot;SELECT tno from teams where name ='&quot;+request.getParameter(&quot;prem_choices_1&quot;)+&quot;'&quot;);

while(res2.next()){

int team_no=res2.getInt(&quot;tno&quot;);

res2.close();

stmt.executeQuery(&quot;INSERT INTO jtable(aid,tno)VALUES('1','&quot;+team_no+&quot;')&quot;);
res2.next();
}

ResultSet res3=stmt.executeQuery(&quot;SELECT tno from teams where name ='&quot;+request.getParameter(&quot;prem_choices_2&quot;)+&quot;'&quot;);

while(res3.next()){

int team_no=res2.getInt(&quot;tno&quot;);

res3.close();

stmt.executeQuery(&quot;INSERT INTO jtable(aid,tno)VALUES('1','&quot;+team_no+&quot;')&quot;);
res3.next();
}

//clean up


stmt.close();
con.close(); %>

Thanks
Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top