Solved

insert data into database

Posted on 2003-10-21
7
220 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
ID: 9596498
0
 

Author Comment

by:CruZ3r
ID: 9596557
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
ID: 9596586
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
ID: 9596761
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
ID: 9647347
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
Some of the SEO trends we might expect in 2017.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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