2014-02-14 30 views
0

我有项目,在这里我只是将这两个值保存到MySQL数据库,它工作fine.my要求是我想通过邮递员发送数据,但这些值没有保存到数据库,我没有得到任何异常,请帮助我如何解决这个问题。 mycode的是:邮政方法不适用于邮递员(铬扩展)

homepage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
<script type="text/javascript"> 
function validateForm() 
{ 
var x=document.getElementById("location").value; 
if(x == "") 
{ 
    alert("Please Enter The Location!"); 

    return false; 
} 
var y=document.getElementById("time").value; 
if(y == "" ) 
{ 
    alert("Please Enter The Time!"); 

    return false; 
} 
var digits = ""; 
var temp; 

for (var i = 0; i < document.getElementById("time").value.length; i++) { 
    temp = document.getElementById("time").value.substring(i, i + 1); 
    if (digits.indexOf(temp) == -1) { 
     alert("Please enter correct time"); 
     document.getElementById("time").focus(); 
     return false; 
    } 
} 
} 
</script> 
</head> 
<body bgcolor="cyan"> 
<form name="myForm" method="post" action="insert.jsp" onsubmit="return validateForm()"> 
<div style="background-image:url(bg.jpg);"> 
<center><h1><font color="red">TRAFFIC INFORMATION SYSTEM</font></h1></center><br> 
</div> 
<hr size="10" color="red"> 
<center> 
<table cellpadding="12"> 
<tr> 
<td align="left"> 
Location</td><td> <input type="text" name="location"></td> 
<tr> 
<td align="right"> 
Expected Time 
</td> 
<td align="left"> 
<input type="text" size="3" name="time" maxlength="3"> 
Minutes 
</td> 
</tr> 
<tr><td></td> 
<td><input type="image" src="submit.gif" alt="Submit" width="48" height="48"/></td></tr> 
</table> 
</center> 
</form> 
</body> 
</html> 

insert.jsp

<% 
DBCreation creation; 
Connection connection; 
String location; 
String time; 

    location=request.getParameter("location"); 
    time=request.getParameter("time"); 

    connection=new DBCreation().getConnection(); 

    try { 
     PreparedStatement statement=connection.prepareStatement("insert into Jam_Info values(?,?)"); 
     statement.setString(1, location); 
     statement.setString(2, time); 
     int i=statement.executeUpdate(); 
     if(i>0) 
     { 
      RequestDispatcher dispatcher=request.getRequestDispatcher("success.jsp"); 
      dispatcher.forward(request, response); 
     } 
    } catch (SQLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

%> 

回答

1

你将不得不写提交,保存数据

connection.commit(); 

您还没有关闭连接。

connection.close(); 

把它写在Finally块中。

+0

是我的问题是关联这个语句 – kumar

+0

是的......只是提交连接对象。数据将被保存在数据库中。 –

+0

只是试试这个..你的问题将得到解决。 –