Package com. Ls. Servlet.
The import com. Ls. Beans. Result;
The import com. Ls. Beans. Sender;
The import com. Ls. Bean. The user;
The import com. Ls. Service. ExpressService;
The import com. Ls. Service. Impl. ExpressServiceImpl;
The import javax.mail. Servlet. ServletException;
The import javax.mail. Servlet. The annotation. WebServlet;
The import javax.mail. Servlet. HTTP. HttpServlet;
The import javax.mail. Servlet. HTTP. It;
The import javax.mail. Servlet. HTTP. HttpServletResponse;
Import the Java. IO. IOException;
@ WebServlet ("/express/* ")
Public class ExpressServlet extends BaseServlet {
Private ExpressService es=new ExpressServiceImpl ();
Private result rs=new result ();
Public void sender (it request, HttpServletResponse response) throws ServletException, IOException {
String sname=request. The getParameter (" sname ");
String price=request. The getParameter (" price ");
String phone=request. The getParameter (" phone ");
Sender send=new sender ();
System. The out. Println (send);
Send. SetSname (sname);
Send the setPrice (price);
Send the setPhone (phone);
Boolean b=es. Send (send);
{if (b)
Rs. SetFlag (true);
System. The out. Println (" user information to add success ");
} else {
Rs. SetFlag (false);
System. The out. Println (" user information to add failure ");
}
WriteValue (rs, response);
}
}
Dao layer
Package com. Ls. Dao. Impl;
The import com. Ls. Beans. Sender;
The import com. Ls. Dao. ExpressDao;
The import com. Ls. Util. DruidUtil;
The import org. Springframework. JDBC. Core. JdbcTemplate;
Import the Java. SQL. Connection;
Import of Java, SQL PreparedStatement;
Import the Java. SQL. SQLException;
Public class ExpressDaoImpl implements ExpressDao {
Tl=new private JdbcTemplate JdbcTemplate (DruidUtil getDataSource ());
@ Override
Public Boolean send (sender s) {
Connection conn=null;
PreparedStatement PSMT=null;
String SQL="insert into sender values (null,? ,? ,?) ";
Try {
Conn=DruidUtil. GetConnection ();
PSMT=conn. PrepareStatement (SQL);
PSMT. SetString (1, s.g etSname ());
PSMT. SetString (2, s.g etPrice ());
PSMT. SetString (3, s.g etPhone ());
PSMT. ExecuteUpdate ();
} the catch (SQLException e) {
e.printStackTrace();
} the finally {
DruidUtil. Close (conn, PSMT);
}
return false;
}
}
CodePudding user response:
Check the variable type and the field typeCodePudding user response:
String SQL="insert into sender values (null,? ,? ,?) ";Insert into sender (sname, price, phone) values (?,?,?,?,? ,? ,?)
Id can be set on the, have a try
CodePudding user response:
Transfer you to track the SQL inside whether or not to bring the value,