2014-11-05 48 views
1

我创建一个盒子,我张贴job title以及job description,它会上载到数据库,但我不知道我要去哪里错了.....我的文本信息没有被上传到数据库中?

正如我提交它说:

HTTP Status 500 - An exception occurred processing JSP page /submit_job_forum.jsp at line 11 

这里是我的forum.jsp

<div id="forum2"> 
     <h1 style="text-align: center;">Want to post on going walking,<br>Post your job description here.</h1> 
     <form id="forum2_form" method="post" action="submit_job_forum.jsp"> 
      <p> 
      <label>Job title:</label> 
      <input type="text" class="" placeholder="e.g XXX Referral program for freshers." name="job_title"/> 
      </p> 
      <p> 
      <label>Description:</label> 
      <textarea class="question_ask_style" rows="3" cols="40" placeholder="Type description here.." name="job_description"></textarea> 
      </p> 

      <div id="submit_btn"> 
      <input type="submit" value="Submit Question" /> 
      </div> 
     </form> 
    </div> 

这里是我的submit_job_forum.jsp

<%@ page import="java.sql.*" %> 

<% 
    String job_title=request.getParameter("job_title"); 
    String job_description=request.getParameter("job_description"); 

    Class.forName("com.mysql.jdbc.Driver"); 
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:8888/login", "root", "1234"); 
    Statement st=con.createStatement(); 
    ResultSet rs; 
    rs=st.executeQuery("insert into job_post('id', 'job_title', 'job_description') VALUES (' ', '"+job_title+"', '"+job_description+"')"); 
    response.sendRedirect("forum.jsp"); 
%> 

在这里,我创建了这个表数据库:

create table `job_post`(
`id` int(100) unsigned NOT NULL auto_increment, 
`job_title` varchar(100) NOT NULL, 
`job_description` varchar(1000) NOT NULL, 
PRIMARY KEY(`id`) 
)ENGINE= InnoDB default charset=latin1; 

请帮助:(

+0

为什么你不在JSP中使用一些异常处理来检查可能的异常? – RE350 2014-11-05 08:22:33

回答

1

小心周围的列名撇号,您必须使用该字符(`)或只是省略它(只要你避开保留字)。 虽然值,它只是很好。

rs=st.executeQuery("insert into job_post(`id`, `job_title`, `job_description`) 
    VALUES (' ', '"+job_title+"', '"+job_description+"')"); 
相关问题