consulta de mysql com base em variáveis ​​jQuery em página jsp

votos
0
<%@ page import = java.util.*,java.io.*,java.sql.* %>
<!DOCTYPE html>
<html>
<head>
  <title>SASG v1.0</title>
  <link rel=stylesheet href=main1.css/>
  <script type=text/javascript src=jquery-3.3.1.js></script>
</head>
<body>
<script>
    function subject_list()
    {
        var course = $('#course-cb option:selected').text();
        var stream = $('#stream-cb option:selected').text();
        var year = $('#year-cb option:selected').text();
        <%
            try
            {

                Class.forName(com.mysql.jdbc.Driver);
                Connection con = DriverManager.getConnection(jdbc:mysql://localhost:3306/timetabledb,root,`);
                Statement stmt = con.createStatement();
                String query = select * from subjects;
                ResultSet rs = stmt.executeQuery(query);
                for(int i=0;rs.next();i++)
                {
        %>

        $('#tbl').append('<tr><td><input type=checkbox></input></td><td><%=rs.getString(subject_code)%></td><td><%=rs.getString(subject_name)%></td><td><%=rs.getString(subject_code)%></td><td><%=rs.getString(subject_code)%></td><td><%=rs.getString(subject_code)%></td><td><%=rs.getString(subject_code)%></td><td><%=rs.getString(subject_code)%></td><td><%=rs.getString(subject_code)%></td></tr>');

        <%
                }
             }
            catch(Exception e)
            {

            }
        %>
    }
    function change()
    {
        var selectedItem = $('#course-cb option:selected').text();
        if(selectedItem==B.Tech)
        {
            $('#stream-cb').find('option').remove().end();
            $('#stream-cb').append($(<option></option>).attr(value,BT).text(BioTechnology));
            $('#stream-cb').append($(<option></option>).attr(value,CH).text(Chemical Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,EE).text(Electrical Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,IT).text(Information Technology));
            $('#stream-cb').append($(<option></option>).attr(value,CSE).text(Computer Science & Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,CE).text(Civil Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,ECE).text(Electronics & Communications Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,ME).text(Mechanical Engineering));

            $('#year-cb').find('option').remove().end();
            $('#year-cb').append($(<option></option>).attr(value,1).text(1));
            $('#year-cb').append($(<option></option>).attr(value,2).text(2));
            $('#year-cb').append($(<option></option>).attr(value,3).text(3));
            $('#year-cb').append($(<option></option>).attr(value,4).text(4));
        }
        if(selectedItem==B.Pharm)
        {
            $('#stream-cb').find('option').remove().end();
            $('#stream-cb').append($(<option></option>).attr(value,P).text(Pharmacy));

            $('#year-cb').find('option').remove().end();
            $('#year-cb').append($(<option></option>).attr(value,1).text(1));
            $('#year-cb').append($(<option></option>).attr(value,2).text(2));
            $('#year-cb').append($(<option></option>).attr(value,3).text(3));
            $('#year-cb').append($(<option></option>).attr(value,4).text(4));
        }
        if(selectedItem==M.Tech)
        {
            $('#stream-cb').find('option').remove().end();
            $('#stream-cb').append($(<option></option>).attr(value,BT).text(BioTechnology));
            $('#stream-cb').append($(<option></option>).attr(value,ECE).text(Electronics & Communications Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,CSE).text(Computer Science & Engineering));
            $('#stream-cb').append($(<option></option>).attr(value,TE).text(Thermal Engineering));

            $('#year-cb').find('option').remove().end();
            $('#year-cb').append($(<option></option>).attr(value,1).text(1));
            $('#year-cb').append($(<option></option>).attr(value,2).text(2));
        }
        if(selectedItem==M.B.A.)
        {
            $('#stream-cb').find('option').remove().end();
            $('#stream-cb').append($(<option></option>).attr(value,BA).text(Business Administration));

            $('#year-cb').find('option').remove().end();
            $('#year-cb').append($(<option></option>).attr(value,1).text(1));
            $('#year-cb').append($(<option></option>).attr(value,2).text(2));
        }
        if(selectedItem==M.C.A.)
        {
            $('#stream-cb').find('option').remove().end();
            $('#stream-cb').append($(<option></option>).attr(value,INT).text(Integrated (2-Year)));
            $('#stream-cb').append($(<option></option>).attr(value,INT).text(Regular (3-Year)));            

            $('#year-cb').find('option').remove().end();
            $('#year-cb').append($(<option></option>).attr(value,1).text(1));
            $('#year-cb').append($(<option></option>).attr(value,2).text(2));
            $('#year-cb').append($(<option></option>).attr(value,3).text(3));
        }
        if(selectedItem==M.Pharm)
        {
            $('#stream-cb').find('option').remove().end();
            $('#stream-cb').append($(<option></option>).attr(value,PH).text(Pharmacology));
            $('#stream-cb').append($(<option></option>).attr(value,PH).text(Pharmaceutics));

            $('#year-cb').find('option').remove().end();
            $('#year-cb').append($(<option></option>).attr(value,1).text(1));
            $('#year-cb').append($(<option></option>).attr(value,2).text(2));
        }
    }
</script>
    <div id=head>
        <p>Assign Subjects & Faculty</p>
    </div>
    <div id=details>
        <span id=course>
            <select id=course-cb onchange=change();>
                <option value= selected hidden>--Choose course--</option>
                <option value=B.Tech>B.Tech</option>
                <option value=M.B.A.>M.B.A.</option>
                <option value=B.Pharm>B.Pharm</option>
                <option value=M.Pharm>M.Pharm</option>
                <option value=M.Tech>M.Tech</option>
                <option value=M.C.A.>M.C.A.</option>
            </select>
        </span>
        <span id=stream>
            <select id=stream-cb>
                <option value= selected hidden>--Choose stream--</option>
            </select>
        </span>
        <span id=year>
            <select id=year-cb>
                <option value= selected hidden>--Choose year--</option>
            </select>
        </span>
        <span>
            <button name=subject_gen onclick=subject_list();>List Out Subjects</button>
        </span>
    </div>
    <br>
    <div>
        <table id=tbl border=1 cellspacing=3>
            <tr>
                <th rowspan=2>Select</th>
                <th rowspan=2>Subject Code</th>
                <th rowspan=2>Subject Name</th>
                <th colspan=6>Assigned Faculties</th>
            </tr>
            <tr>
                <th>A</th>
                <th>B</th>
                <th>C</th>
                <th>D</th>
                <th>E</th>
                <th>F</th>
            </tr>
        </table>
    </div>
</body>
</html>

esta é a minha página jsp, eu quero executar uma consulta MySQL utilizando o código JDBC com valores selecionados em três menus em mesma página, como eu poderia fazer o mesmo. Eu tentei, mas ele sempre gera um erro dizendo algo como, Inserir um ponto e vírgula. Estou totalmente confuso, por favor ajude.

Na função chamada subject_list(), as 3 variáveis declaradas ter de ser usado na consulta.

Publicado 08/11/2018 em 06:57
fonte usuário
Em outras línguas...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more