12:57 pm - Saturday November 1, 2014

Struts with jdbc Integration Tutorial with example program

Project Structure:











Jar Files:








 Following is the list of required JAR files to be added in Java Class Path of your project. Download displaytag JAR files from




import java.sql.*;

public class InsertDataBase {
	public void insertData1(String name, String degree, String mobno)
			throws Exception {
		System.out.println("jdbc connection");
		String url = "jdbc:oracle:thin:@localhost:1521:XE";
		String un = "system";
		String pwd = "system";
		String name1 = name;
		String degree1 = degree;
		String mobno1 = mobno;
		try {
			Connection c = DriverManager.getConnection(url, un, pwd);
			try {
				Statement st = c.createStatement();
				int val = st
						.executeUpdate("INSERT INTO UserDetails(name,degree,mobno) VALUES('"
								+ name1
								+ "','"
								+ degree1
								+ "','"
								+ mobno1
								+ "')");
				System.out.println("1 row affected");
			} catch (SQLException ex) {
				System.out.println("SQL statement is not executed!" + ex);
		} catch (Exception e) {


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class MyController extends Action {
	public ActionForward execute(ActionMapping map, ActionForm fm,
			HttpServletRequest req, HttpServletResponse res) throws Exception {
		HttpSession ses = req.getSession(true);

		MyModel m = (MyModel) fm;
		String name = m.getName();
		String degree = m.getDegree();
		String mobno = m.getName();
		InsertDataBase IB = new InsertDataBase();
		IB.insertData1(name, degree, mobno);
		ses.setAttribute("name", name);
		ses.setAttribute("degree", degree);
		ses.setAttribute("mobno", mobno);
		if (name.equals("") || degree.equals("") || mobno.equals("")) {
			return map.findForward("error");
		return map.findForward("success");



import org.apache.struts.action.ActionForm;

public class MyModel extends ActionForm {
	private String name;
	private String degree;
	private String mobno;

	public String getMobno() {
		return mobno;

	public void setMobno(String mobno) {
		this.mobno = mobno;

	public String getDegree() {
		return degree;

	public void setDegree(String degree) {
		this.degree = degree;

	public void setName(String n) {
		name = n;

	public String getName() {
		return name;


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">






			<web-resource-name>My secure resources</web-resource-name>
			<description>Resources to be placed under security control.</description>


		<description>The role allowed to access our content</description>



<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"

		<form-bean type="MyModel" name="model" />
		<action path="/myActionForm" type="MyController" name="model"
			<forward name="success" path="/success.jsp" />
			<forward name="error" path="/fail.jsp" />



















































Struts with jdbc Integration Tutorial with example program

Filed in: Z-AStruts Codes

No comments yet.

Leave a Reply

Facebook Auto Publish Powered By : XYZScripts.com

Social Widgets powered by AB-WebLog.com.