Solved

Save data into access

Posted on 2006-10-24
4
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Apache and Apache Tomcat.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Marketing can be an uncomfortable undertaking, especially if your material is technology based. Luckily, we’ve compiled some simple and (relatively) painless tips to put an end to your trepidation and start your path to success.
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now