我想在确认之前确认用户在数据库中插入数据。
InsertData.java Servlet在数据库中插入数据如下:
public class InsertData extends HttpServlet {
private PrintWriter out;
private String M_ID;
private String E_MERC_ID;
private String C_ID;
private String B_ID;
private String M_ID;
private char P3_STATUS;
private static final long serialVersionUID = 1L;
public InsertData() {
super();
// TODO Auto-generated constructor stub
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date currentDate = new Date();
String T_DATE_TIME = dateFormat.format(currentDate);
System.out.println(T_DATE_TIME);
String E_TXN_REF_NO = request.getParameter("E_TXN_REF_NO");
String T_REF_NO = request.getParameter("T_REF_NO");
String E_TXN_AMOUNT = request.getParameter("E_TXN_AMOUNT");
M_ID = "VODAESP";
E_MERC_ID = "VODATUPMU1";
C_ID = "am418785";
B_ID = "CIT";
M_ID = "123456";
P_STATUS = 'Y';
try {
response.setContentType("text/html");
out = response.getWriter();
final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
final String DB_URL = "jdbc:oracle:thin:@10.23.34.4:1521:abc";
// Database credentials
final String USER = "abc";
final String PASS = "abc";
// Step 1. Load the JDBC driver
Driver driver = (Driver) Class.forName(JDBC_DRIVER).newInstance();
DriverManager.registerDriver(driver);
// Step 2. Create a Connection object
Connection con = DriverManager.getConnection(DB_URL, USER, PASS);
con.setAutoCommit(false);
Statement s = con.createStatement();
System.out.println("got connection");
// // Step 4. Use the same Statement object to obtain a ResultSet
// object
String sql = "INSERT INTO E2_PAYMENT"
+ "(E_TXN_REF_NO,M_ID,E_MERC_ID,C_ID,"
+ "T_REF_NO,B_ID,M_ID,T_DATE_TIME,E_TXN_AMOUNT,P_STATUS)"
+ " values('" + E_TXN_REF_NO + "','" + M_ID + "','"
+ E_MERC_ID + "','" + C_ID + "','" + T_REF_NO
+ "','" + B_ID + "','" + M_ID + "',TO_DATE('"
+ T_DATE_TIME + "','YYYY-MM-DD'),'" + E_TXN_AMOUNT
+ "','" + 3_STATUS + "')";
s.executeUpdate(sql);
s.close();
con.close();
// request.setAttribute("con", con);
request.getRequestDispatcher("RetriveData").forward(request,
response);
} catch (ClassNotFoundException e1) {
// JDBC driver class not found, print error message to the console
System.out.println(e1.toString());
out.println(e1.toString());
e1.printStackTrace();
} catch (SQLException e2) {
// Exception when executing java.sql related commands, print error
// message to the console
System.out.println(e2.toString());
out.println(e2.toString());
e2.printStackTrace();
} catch (Exception e3) {
// other unexpected exception, print error message to the console
System.out.println(e3.toString());
out.println(e3.toString());
e3.printStackTrace();
}
}}
我想在用户确认需要帮助后提交此查询吗?
答案 0 :(得分:2)
在您的页面上,您可以添加类似的内容;
onclick="javascript:return confirm('Are you sure?')"
答案 1 :(得分:1)
首先导航到确认页面然后,如果用户确认,则执行insertData.java
答案 2 :(得分:1)
你应该在去服务器前询问确认,然后才到达 首先进行处理没有意义 在服务器上,然后回到客户端进行确认,你可以单手去做
我建议使用jconfirm