10 April, 2010

Database Connectivity in JSP

Database connectivity using JSP with MS Access

First Your need to post all the arguments from one webpage to another for that you need to write like this
in your form tag

method="post" action="database.jsp"

 Database connectivity page

// database.jsp


  <%@page import="java.net.URLEncoder" %>
  <%@ page import="java.net.*"%>
  <%@ page import="java.sql.*"%>
  <%

  try
  {
   String s1=request.getParameter("t1");
   String s2=request.getParameter("t2");
   String s3=request.getParameter("t3");
   String s4=request.getParameter("t4");

               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con=DriverManager.getConnection("jdbc:odbc:login"," "," ");
    

/* login is the your System DNS driver name which can be created as by these steps      go to control panel  double click on Administrative tools then double click on Datasource (ODBC) then select the System DNS from upper bar then click to add and select the Microsoft Access Driver (.mdb) then click on finish give the Data source name and click on select and selct the access file where it present then click ok every where and come out Note that Data Source name is your System DNS which will be written instead of Login in connection statement
             
*/

           Statement st=con.createStatement();
      
           st.executeUpdate("INSERT INTO profile VALUES ('" + s1 + "','" + s2 + "','" + s3 + "','" + s4 +"')");

con.close();
}                                      
catch(Exception e){}

%>

No comments:

Post a Comment