如何在此Java程序中实现属性文件?

问题描述 投票:-2回答:1

如何在此Java Servlet程序中实现属性文件或属性?以及如何在数据库中存储数据

代码:-公共类InsertData扩展HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
     try (PrintWriter out = response.getWriter()) {
        try{
    String dbDriver = "com.mysql.jdbc.Driver"; 
    String dbURL = "jdbc:mysql://localhost:3306/"; 
    String dbName = "demo"; 
    String dbUsername = "root"; 
    String dbPassword = "root"; 

    Class.forName(dbDriver); 
    Connection con = DriverManager.getConnection(dbURL + dbName, 
                                                 dbUsername,  
                                                 dbPassword); 




            PreparedStatement st = con.prepareStatement("insert into details values (?,?,?)");
             st.setString(1, request.getParameter("first_name")); 


            st.setString(2, request.getParameter("last_name"));

             st.setString(3, request.getParameter("Address"));

            st.executeUpdate();

            st.close();
            con.close();
        }

             catch(Exception ex) {
                 ex.printStackTrace(out);
                 }         
      }}}
java mysql sql-server jsp servlets
1个回答
0
投票

您可以使用this example。或者,您可以使用this之类的东西。

© www.soinside.com 2019 - 2024. All rights reserved.