QA@IT
«回答へ戻る

回答を投稿

僕が昔書いたプログラムを掲載してみます。
参考にならかったら、疑問な点をコメント下さい。

// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package tera;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**

  • RegistAction.java created by EasyStruts - XsltGen.
  • http://easystruts.sf.net
  • created on 12-21-2006
  • XDoclet definition:
  • @struts:action path="/Regist" name="RegistForm" input="registConfirm.jsp"
  • @struts:action-forward name="success" path="registComplte.jsp"
    */
    public class RegistAction extends Action {

    // --------------------------------------------------------- Instance Variables

    // --------------------------------------------------------- Methods

    /**

    • Method execute
    • @param ActionMapping mapping
    • @param ActionForm form
    • @param HttpServletRequest request
    • @param HttpServletResponse response
    • @return ActionForward
    • @throws Exception
      */
      public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception{

      RegistForm sap = (RegistForm)form;
      String ID1 = sap.getId();
      String PW1 = sap.getPw();
      String NAME1 = sap.getName();

      try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      Connection dbConn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mymall", "921", "5544");
      Statement stmt = dbConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
      stmt.executeUpdate("insert into mytable values ('" + ID1 + "','" + PW1 + "','" + NAME1 + "')");

      stmt.close();
      dbConn.close();         
      

      } catch (Exception e) {
      e.printStackTrace();
      }

      return (mapping.findForward("success"));

    }

}

僕が昔書いたプログラムを掲載してみます。
参考にならかったら、疑問な点をコメント下さい。

// Created by Xslt generator for Eclipse.
// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package tera;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/** 
 * RegistAction.java created by EasyStruts - XsltGen.
 * http://easystruts.sf.net
 * created on 12-21-2006
 * 
 * XDoclet definition:
 * @struts:action path="/Regist" name="RegistForm" input="registConfirm.jsp"
 * @struts:action-forward name="success" path="registComplte.jsp"
 */
public class RegistAction extends Action {

	// --------------------------------------------------------- Instance Variables

	// --------------------------------------------------------- Methods

	/** 
	 * Method execute
	 * @param ActionMapping mapping
	 * @param ActionForm form
	 * @param HttpServletRequest request
	 * @param HttpServletResponse response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward execute(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws Exception{
			
		RegistForm sap = (RegistForm)form;
		String ID1 = sap.getId();
		String PW1 = sap.getPw();
		String NAME1 = sap.getName();
		
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection dbConn =	DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mymall", "921", "5544");
			Statement stmt = dbConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			stmt.executeUpdate("insert into mytable values ('" + ID1 + "','" + PW1 + "','" + NAME1 + "')");
			
			stmt.close();
			dbConn.close();			

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return (mapping.findForward("success"));
		
	}
	
}