2016-11-03 2 views
0

Leave.jsp Jsp-Seite für den Urlaub gelten.Die Ausnahme 'Anweisung konnte nicht ausgeführt werden' während der Eingabe des Datums in Tabelle

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <head> 
<title> 
    Leave Apply</title> 
    <style> 
    body { 
    font-family: Times New Roman; 
    font-size: 200%; 
     } 
    table { 
    border: 0px; 
    font-family: Time New Roman; 
    font-size: 50%; 
    width: 30%; 
    background-color: orange; 
    padding: 15px; 
    } 
     </style> 
</head> 
<body > 
<center> 
    Apply Leave<br/><br/> 
    <form method="post" action="leaveservlet" name="form1"> 
     <table> 
      <tr> 
       <td> 
        Subject: 
       </td> 
       <td> 
        <input type="text" name="name" placeholder="Subject"> 
       </td> 
       </tr> 
       <tr> 
       <td> 
        Content: 
       </td> 
       <td> 
        <textarea name="content" rows="8" cols="30"></textarea> 
       </td> 
       </tr> 
       <tr> 
       <td> 
        From: 
       </td> 
       <td> 
        <input type="date" name="from"> 
       </td> 
       </tr> 
        <tr> 
       <td> 
        Till: 
       </td> 
       <td> 
        <input type="date" name="till"> 

       </td> 
       </tr> 
       <input type="hidden" name="status" value="0"> 

       <tr> 
        <td></td> 
        <td><input type="submit" name="submit" value="Leave  Apply">&nbsp&nbsp<input type="reset" name="reset" value="Reset"></td> 

       </tr> 
     </table> 
    <br/> 

    </form> 
    </center> 

    </body> 
    </html> 

leaveservlet Thema, Inhalt, von und bis zu diesem Servlet geschrieben wird und ich analysieren dann die Zeichenfolge Datum Simple verwenden.

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException { 
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); 
    PrintWriter out= response.getWriter(); 
    String sub= request.getParameter("name"); 
    String con= request.getParameter("content"); 
    String from= request.getParameter("from"); 
    String till= request.getParameter("till"); 
    String status= request.getParameter("status"); 
    int i = Integer.parseInt(status); 
    Session s= HibernateUtil.getSessionFactory().openSession(); 
    Transaction t= s.beginTransaction(); 
    Leave l= new Leave(); 
    l.setSubject(sub); 
    l.setContent(con); 
    try{ 
    l.setFrom(fmt.parse(from)); 
    l.setTill(fmt.parse(till)); 
    } 
    catch(Exception e){ 
     out.print("sorry"); 
    } 
    l.setStatus(i); 
    s.save(l); 
    t.commit(); 
    s.close(); 
} 

Leave.java

public class Leave implements java.io.Serializable { 


private Integer id; 
private String subject; 
private String content; 
private Date from; 
private Date till; 
private Integer status; 

public Leave() { 
} 


public Leave(String subject, String content, Date from) { 
    this.subject = subject; 
    this.content = content; 
    this.from = from; 
} 
public Leave(String subject, String content, Date from, Date till, Integer status) { 
    this.subject = subject; 
    this.content = content; 
    this.from = from; 
    this.till = till; 
    this.status = status; 
} 

public Integer getId() { 
    return this.id; 
} 

public void setId(Integer id) { 
    this.id = id; 
} 
public String getSubject() { 
    return this.subject; 
} 

public void setSubject(String subject) { 
    this.subject = subject; 
} 
public String getContent() { 
    return this.content; 
} 

public void setContent(String content) { 
    this.content = content; 
} 
public Date getFrom() { 
    return this.from; 
} 

public void setFrom(Date from) { 
    this.from = from; 
} 
public Date getTill() { 
    return this.till; 
} 

public void setTill(Date till) { 
    this.till = till; 
} 
public Integer getStatus() { 
    return this.status; 
} 

public void setStatus(Integer status) { 
    this.status = status; 
} 

Exception Exception thrown on browser

Antwort

0

Dieses Problem tritt wegen der falschen Daten kommt (using SQL reserved/syntax keywords 'from' 'select' ,etc..) die Sie von der Eingabeseite für diese Felder senden:

subject, content, from 

Versuchen Sie einfach einige einfache Daten wie subject = subjectA, content = contentB, from = FROMUS

zu setzen
Verwandte Themen