表單用於從客戶那裏獲取信息。 這種形式有幾個領域。 來自多個字段的數據必須保存在一列中。 其餘的需要保存在另一個表中。如何將customer_id從第一個表的customer_id中獲取到第二個表中?
下面是我使用
package web.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ead.DBConnect;
/**
* Servlet implementation class New
*/
public class CustomerReg extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public CustomerReg() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name = request.getParameter("name");
String email = request.getParameter("email");
//String Password = request.getParameter("Password");
String addressno = request.getParameter("addressno");
String city = request.getParameter("city");
String country = request.getParameter("country");
String postalcode = request.getParameter("postalcode");
String telnum = request.getParameter("telnum");
DBConnect dbconnect = new DBConnect();
dbconnect.update("INSERT INTO customer (customer_name, email, address_no, city, country, postal_code) VALUES('"+name+"','"+email+"','"+addressno+"', '"+city+"','"+country+"','"+postalcode+"')");
int[] id = dbconnect.selectInt("Select LAST_INSERTID()", "customer_id");
dbconnect.update("INSERT INTO customer_tel (customer_id, tel_no) VALUES('+id+', '"+telnum+"')");
}
}
如何從同一個表中設置數據到兩個表的線?
我想你需要澄清你的問題。你的意思是在同一個語句中插入兩個表嗎?你不能,但你可以在同一個事務中插入兩個表。並請使用參數爲 – 2012-01-05 06:57:00