Solved

Save data into access

Posted on 2006-10-24
4
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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