Solved

insert data into database

Posted on 2003-10-21
7
217 Views
Last Modified: 2010-04-01
How to create a simple page of inserting data into a database?
0
Comment
Question by:CruZ3r
7 Comments
 
LVL 3

Expert Comment

by:applekanna
Comment Utility
0
 

Author Comment

by:CruZ3r
Comment Utility
err tatz showing/accessing the database in jsp.... i wan to insert data to the database using jsp

thx anyway =)
0
 
LVL 3

Accepted Solution

by:
applekanna earned 35 total points
Comment Utility
That is easy, just follow the guide there
and replace
executeQuery with executeUpdate  like this.

<% Statement statement =
               connection.createStatement();
     ResultSet resultSet =
         statement.executeUpdate("insert into table "); %>


Hope this helps.
DO u need more ...
Cheers1
0
 
LVL 1

Expert Comment

by:yapsing
Comment Utility
get your items like this:
<%
 float netsales        = Float.parseFloat(request.getParameter("netsales"));
 float food            = Float.parseFloat(request.getParameter("food"));

//create your connection here

 PreparedStatement stmt = C.prepareStatement("insert into "+ tab +" (date,netsales,food) values (now(),?,?)");
 stmt.setFloat(1,netsales);
 stmt.setFloat(2,food);
 stmt.executeUpdate();
 response.sendRedirect("wherever u wanna go next");

%>
0
 

Expert Comment

by:nasarudin
Comment Utility
Below is the example to insert data into oracle database.
Hope this could help.

<%@ page import = "java.sql.*"%>
<%@ page import = "oracle.sql.*"%>
<%@ page import = "oracle.jdbc.driver.*"%>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@myserver.company.com:1521:sidname","scott","tiger");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

String strDeptNo = request.getParameter("txtDeptNo");
String strDeptName = request.getParameter("txtDeptName");
String strLoc = request.getParameter("txtLoc");

String strSQL = "INSERT INTO DEPT (DEPTNO, DNAME, LOC ) " +
                        "VALUES ( '" + strDeptNo + "', '"  + strDeptName + "', '" + strLoc + "')";

try{
      stmt.executeUpdate(strSQL);
}catch(SQLException SQLEx){
      out.println("Error : " + SQLEx.getMessage());
      if(1==1)return;
}
%>
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now