Solved

insert data into database

Posted on 2003-10-21
7
222 Views
Last Modified: 2010-04-01
How to create a simple page of inserting data into a database?
0
Comment
Question by:CruZ3r
[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
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

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 147
spring dependency injection using java config 2 94
authenticate preemptively soap ui option 3 179
struts exact match support 3 64
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

739 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