Tue Apr 21, 2009 6:49 am
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.HashMap;
//import com.lara.rms.db.ConnectionPool;
import java.util.Map;
public class AddConstructionServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println("*************************");
System.out.println(" BUSINESS LOGIC ");
System.out.println("*************************");
PrintWriter out = response.getWriter();
Connection con=null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:dberp","system","tiger");
}
catch(Exception e)
{
e.printStackTrace();
}
/* String UserName = null;
String Name = null;
String Email = null;
String Address = null;
String City= null;
String State = null;
String Pincode = null;*/
Map allParams = request.getParameterMap();
//RequestDispatcher dispatcher = null;
String UserName[] = (String[])allParams.get("UserName");
String Name[] = (String[])allParams.get("Name");
String Email[] = (String[])allParams.get("Email");
String Address[] = (String[])allParams.get("Address");
String City []= (String[])allParams.get("City");
String State[] = (String[])allParams.get("State");
String Pincode[] = (String[])allParams.get("Pincode");
Statement stmt=null;
String sql = "insert into Supplier(UserName, Name, Email, Address, City, State, Pincode)" +
" values('" + UserName + "','" + Name + "','" + Email + "'," + Address + ",'" + City + "'," + State + ",'" + Pincode + "')";
System.out.println("sql:"+sql);
out.println("insertation complete");
try
{
stmt = con.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(stmt != null)
{
stmt.close();
stmt= null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
try
{
if(con != null)
{
con.close();
con= null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.