vendredi 29 novembre 2019

How to store the value in mysql database in inside If else statement ? whether it is possible or not?

I have stuck with this concept for the past 2 days, Please help me with this. Thanks in Advance. Let me explain my concepts.

I have attached 2 JSP files along with this, It was to convert the marks into IELTS score. For EX: I have to enter the score like (Listening: 30, Reading: 25, Writing: 31, Speaking:18 ) It want to convert and store into IELTS score in SQL Database like EX:(Listening: 6.5, Reading: 7, Writing:5.8, Speaking: 8). I can able to convert and display the value but I don't know how to store this score into MySQL Database.

Here is my Code :

User.jsp

<html>
<head>
<meta charset="ISO-8859-1">
<title>Enter the value</title>
</head>
<body>
<form method="post" action="convert.jsp">
Enter Mark for Listen (0 to 40): <input type="text" name="score">
<input type="submit" value="submit">
</form>
</body>
</html>

And this convert.jsp will convert the marks into grade.

Convert.jsp

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
    String ints=request.getParameter("score");
     double s=Integer.parseInt(ints);
    double band ;

    if(s>=0 && s<=3) {
        band=0;
        out.print(band);


      } else  if(s>=4 && s<=5) { band=2.5; out.print(band); }

        else  if(s>=6 && s<=7) { band=3; out.print(band); } 

        else  if(s>=8 && s<=10) { band=3.5; out.print(band);}

        else  if(s>=10 && s<=12) { band=4; out.print(band);}

        else  if(s>=13 && s<=15) { band=4.5; out.print(band);} 

        else  if(s>=16 && s<=17) { band=5; out.print(band);}

        else  if(s>=18 && s<=22) { band=5.5; out.print(band);}

        else  if(s>=23 && s<=25) { band=6; out.print(band);}

        else  if(s>=26 && s<=29) { band=6.5; out.print(band);}

        else  if(s>=30 && s<=31) { band=7; out.print(band);}

        else  if(s>=32 && s<=34) { band=7.5; out.print(band);}

        else  if(s>=35 && s<=36) { band=8; out.print(band);}

        else  if(s>=37 && s<=38) { band=8.5; out.print(band);}

        else  if(s>=39 && s<=40) { band=9; out.print(band); }



 %>
</body>
</html>

And here is my database Structure.

Table name : score

---------------------------------------------|
|                                            |
|  Listening | Reading | Writing | Speaking  |
|--------------------------------------------|
|            |         |         |           |
|____________________________________________|     

Here I want to store the score according to marks(Listening,Reading,Writing,Speaking). 1. How to convert for all 4 fields . 2. how can i store the converted score into database. Can anyone help me with this, please? Thanks in Advance.

Aucun commentaire:

Enregistrer un commentaire