gpt4 book ai didi

java - 如何在使用 Servlet 和 JSP 提交数据库插入之前获得用户确认?

转载 作者:行者123 更新时间:2023-11-29 01:39:31 25 4
gpt4 key购买 nike

我想在提交之前确认用户在数据库中插入数据。

在数据库中插入数据的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();

}
}}

我想在用户确认需要帮助后提交此查询?

最佳答案

在您的页面上,您可以添加类似的内容;

onclick="javascript:return confirm('Are you sure?')"

关于java - 如何在使用 Servlet 和 JSP 提交数据库插入之前获得用户确认?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29599034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com