0

I have a table called school and a table called students.
I have a foreign key in students called school_id which is connected with table school , field id.
I made a form where field **title** appears to the registration form of the student.
The problem is that i want title to appear as it does but when submiting the form the school_id must be written in the database.

Here is the code:

<select name="SCHOOL_ID"   />
       <%
    Class.forName("com.mysql.jdbc.Driver");
    java.sql.Connection connection =java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/dbproject1","", "");
    String query1 ="SELECT TITLE FROM SCHOOL ";
    java.sql.PreparedStatement Stmt1 = connection.prepareStatement(query1);
    ResultSet rs = Stmt1.executeQuery();                     
while (rs.next()) {
   out.print("<option>");
   out.print(rs.getString("TITLE"));
   out.print("</option>");
}
%>
        </select>

thank you!

Edited by peter_budo: Keep It Clear - Do use code tags when posting any code

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by anand01
0

Many thanks for the reply peter. I 've runned it and show it. It's very good.

The thing is that i have my project almost ready and our teacher asked us not to use servlets.
So i'm stack with it.:-O:(

I can make a selection in my query like :

SELECT ID,TITLE FROM SCHOOL ORDER BY ID

but i don't know how only id will be passed to student's table

For example: The student can see a form with : New York School , London School , Dublin School. But when he choose London School and submits id=23 must be written in student's table.

I've tried so many things.I have a headache!:confused:

<td>
        <select name="SCHOOL_ID"   />
       <%
    Class.forName("com.mysql.jdbc.Driver");
    java.sql.Connection connection =java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/dbproject1","kostas9", "");
    String query1 ="SELECT TITLE , ID FROM SCHOOL ";
    java.sql.PreparedStatement Stmt1 = connection.prepareStatement(query1);
    ResultSet rs = Stmt1.executeQuery();                     
while (rs.next()) {
   out.print("<option>");
   out.print(rs.getString("TITLE"));
   out.print("</option>");
}
%>
                


        </select>
        </td>
0

Hi kostas_213,

you already get good tutorial from Mr.peter_budo... Since you asked,
You can use sessions to achieve that

session.setAttribute( "id", stu_id);
session.setAttribute( "id", stu_id);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.