DemoAction.java
package com.rat.action;
import java.sql.*;
import java.util.ArrayList;
import java.util.Map;
import org.apache.struts2.interceptor.ApplicationAware;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
public class DemoAction extends ActionSupport implements Preparable,ModelDriven
{
DemoBean obj;
Connection con;
Statement stmt;
PreparedStatement ps;
public void prepare() throws Exception
{
obj=new DemoBean();
try
{
Class.forName("com.mysql.jdbc.Driver"); //type 4 driver
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root","rat");//connection
System.out.println("Connection successful:"+con);
stmt=con.createStatement();
}
catch(Exception e)
{
e.printStackTrace();
}
}
_________________________________________________
DemoBean.java
package com.rat.action;
public class DemoBean
{
private String uname="",pass="";
public void setUname(String uname)
{
this.uname=uname;
}
public void setPass(String pass)
{
this.pass=pass;
}
public String getUname()
{
return uname;
}
public String getPass()
{
return pass;
}
}
_________________________________________________
ViewAllAction.java
package com.rat.action;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Map;
import org.apache.struts2.interceptor.ApplicationAware;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
public class ViewAllAction extends ActionSupport implements Preparable,ApplicationAware
{
Connection con;
Statement stmt;
DemoBean obj;
Map application;
public void setApplication(Map application)
{
this.application=application;
}
public void prepare()
{
try
{
Class.forName("com.mysql.jdbc.Driver"); //type 4 driver
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root","rat");//connection
System.out.println("Connection successful:"+con);
stmt=con.createStatement();
}
catch(Exception e)
{
e.printStackTrace();
}
}
No comments:
Post a Comment