有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java与MySQL和Netbeans的斗争

我需要帮助在Netbeans中实现MySQL数据库

基本上,我有两个数据库——一个叫做Words,其中包含5014个不同的单词,另一个叫做definitions,其中包含所有单词的定义

我已经在NetBeans中的下拉列表中实现了单词数据库,这样它就可以显示所有5014个单词,但我很难理解如何实现另一个数据库,这样当用户单击(例如)“放弃”和“提交”按钮时,生成的定义页将只显示放弃的定义,我在定义数据库中有

以下是我的开场白代码:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Online English Dictionary</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <h1 align="center">Hello and welcome to my Online English Dictionary</h1>
        <table align="center"> 
            <thead>
                <tr>
                    <th>This Online English Dictionary uses a 5,000 word list
                        compiled by Professor Mark Davies of Brigham Young University
                        in Provo, Utah.</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>To view a definition of a particular word, please select
                        from the list below.</td>
                </tr>
                <tr>
                    <td>
                        <form action="submit.jsp">
                            <strong>Select a word:</strong>
                            <select name="word_id">
                                <c:forEach var="row" items="${words.rowsByIndex}">
                                    <option><c:out value="${row[1]}"/></option>
                                </c:forEach>
                            </select>
                            <input type="submit" value="submit" name="submit" />
                        </form>
                    </td>
                </tr>
            </tbody>
    </table>
</body>

这是创建我的定义数据库的代码:

 DROP TABLE IF EXISTS Definition; 
CREATE TABLE Definition (
definition_id SMALLINT, 
definition VARCHAR (2500),
word_id VARCHAR (17),
PRIMARY KEY (definition_id),
FOREIGN KEY (word_id) REFERENCES Words(word_id)
);

INSERT INTO Definition (definition)
                    VALUES      ('1.  The first letter of the modern English alphabet.

2.  Any of the speech sounds represented by the letter a.

3.  The first in a series.

4.  Something shaped like the letter A.

5.  A The best or highest in quality or rank: grade A milk.

6.  Music 
            a.  The sixth tone in the scale of C major or the first tone in the relative minor scale.

            b.  A key or scale in which A is the tonic.

            c.  A written or printed note representing this tone.

            d.  A string, key, or pipe tuned to the pitch of this tone.

7.  A One of the four major blood groups in the ABO system. Individuals with this blood group have the A antigen on the surface of their red blood cells, and the anti-B antibody in their blood serum.'),

('vb (tr) 
1. to forsake completely; desert; leave behind: to abandon a baby; drivers had to abandon their cars. 

2.  (Nautical Terms) abandon ship the order given to the crew of a ship that is about to sink to take to the lifeboats

3. to give up completely: to abandon a habit; to abandon hope. 

4. to yield control of or concern in; relinquish: to abandon office. 

5. to give up (something begun) before completion: to abandon a job; the game was abandoned. 

6. to surrender (oneself) to emotion without restraint

7.  (Insurance) to give (insured property that has suffered partial loss or damage) to the insurers in order that a claim for a total loss may be made

n
8. freedom from inhibitions, restraint, concern, or worry: she danced with abandon.');

如果有人能帮忙,那就太好了

谢谢, 詹姆斯


共 (1) 个答案

  1. # 1 楼答案

    您需要将其设置为会话,然后在submit.jsp中读取该值,然后触发另一个查询

    尽管如此,我还是建议不要在SQL查询中使用jstl标记,而是使用MVC模型,这样可以很容易地解决这个问题

    在控制器中设置值并返回jsp。 一旦更改下拉列表,就会触发ajax请求以获取详细信息。 在单独的div中显示详细信息,而无需导航到其他页面

    如果你仍然想继续jstlhere是一个很好的教程,如果你有时间的话

    对于使用JSP的MVC,您可以查看两个教程链接:herehere