2015-03-16 2 views
0

Мне нужна помощь в реализации базы данных MySQL в Netbeans.Борьба с MySQL и Netbeans

В принципе, у меня есть две баз данных - один под названием Слова, с 5,014 различными словами и одного называемых определениями всех слов определений в

Я реализовал базу данных слов в раскрывающийся список в NetBeans. так что он представляет все 5014 слов, но я не понимаю, как реализовать другую базу данных, так что, когда пользователь нажимает, скажем, например, «Abandon» и кнопка «Submit», на странице результатов будет отображаться только определение Abandon, которое Я имею в базе данных определения.

Вот мой код страницы открытия:

<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.'); 

Если кто-то может помочь было бы здорово!

Спасибо, Джеймс

+0

Можете ли вы предоставить код контроллера и сервлета, которые вы настроили JNDI/иначе для подключения к базе данных и того, как вы заполняете значение $ {words}. – Gyan

+0

@Gyanpriya Извините, что я ушел от этого, я сделал SQL-запрос в NetBeans для этого. ' SELECT word_id, слова FROM Words ' – JamesB

ответ

0

Ну вам нужно будет установить, что к сессии, а затем в submit.jsp прочитать это значение, а затем огонь другой запрос.

Это, как говорится, я бы рекомендовал не использовать теги для SQL-запросов jstl и вместо этого использовать модель MVC, где это можно легко позаботиться.

Настройка значений в контроллере и возврат к jsp. onChange выпадающего списка - пожарный запрос ajax, чтобы получить детали. Покажите детали тогда и там в отдельном div без перехода на другие страницы.

Если вы хотите продолжить работу с jstlhere - отличный учебник, если у вас есть время.

Для MVC с JSP вы можете ознакомиться с несколькими учебными ссылками: here и here.

HTH.

Смежные вопросы