?
Solved

Save data into access

Posted on 2006-10-24
4
Medium Priority
?
179 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
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: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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