Solved

insert data into database

Posted on 2003-10-21
7
219 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
console vs log file 16 81
HTML5 vs JSP - REST based application development 4 1,067
JSP How to use numberFormat to display a negative number without parenthesis? 1 164
maven set up 2 143
Read about the ways of improving workplace communication.
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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