Solved

Save data into access

Posted on 2006-10-24
4
176 Views
Last Modified: 2010-04-01
Hi: Can any one please tell me how to i write a JSP code to save the following fields into Access database. Assume that ODBC connection name is Employee.

Thanks.


Name=request.form("Name")
Address=request.form("Address")

0
Comment
Question by:mustish1
  • 3
4 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 17799944
It is not good practice to put your jdbc transactions inside a jsp, it would be better if you follow the mvc pattern. However
you can easily do it like this for just a learning experience. This is assuming that your Database has a name of Database
and that you have your Name and Address field on the page.
 
   <% Connection con; %>
    <% Statement stmt; %>
    <% ResultSet rs; %>
    <% String query; %>
    <% String url; %>
    <% String id; %>
    <%
          name = request.getParameter("Name");
      address = request.getParameter("Address");
       
            if(name != null) {
               
                  try {          

                  <!--Assuming you had setup ODBC-->  
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    url = "jdbc:odbc:Database";
                    con = DriverManager.getConnection(url);
                    stmt = con.createStatement();  

                        <!-- If not use this direct connection
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Database.mdb");
                        stmt = con.createStatement();
                        -->
             
                  query = "INSERT INTO YourTable (Name, Address) VALUES ('"+name+"', '"+address+"')";
                }
                catch (ClassNotFoundException x) {
                    x.printStackTrace();
                }
                catch(SQLException y){
                    y.printStackTrace();
                }
           }
    %>
0
 
LVL 15

Accepted Solution

by:
Javatm earned 500 total points
ID: 17799958
Just change the database name of Database to Employee. If your interested in MVC read this:
http://struts.apache.org/
http://en.wikipedia.org/wiki/Model-view-controller
0
 

Author Comment

by:mustish1
ID: 17799996
Ok thanks. Can you also please tell me the name of any free webserver for microsoft windows which i can install on my PC.

Thanks.

0
 
LVL 15

Expert Comment

by:Javatm
ID: 17807823
Apache and Apache Tomcat.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multiple Images Upload [JSP Web-application] 3 48
AlarmClock Challenge 35 155
struts hibernate integration example 28 149
maven disable workspace resolution 1 42
This article was originally published on Monitis Blog, you can check it  here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sour…
This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question