CruZ3r
asked on
insert data into database
How to create a simple page of inserting data into a database?
ASKER
err tatz showing/accessing the database in jsp.... i wan to insert data to the database using jsp
thx anyway =)
thx anyway =)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
get your items like this:
<%
float netsales = Float.parseFloat(request.g etParamete r("netsale s"));
float food = Float.parseFloat(request.g etParamete r("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("whe rever u wanna go next");
%>
<%
float netsales = Float.parseFloat(request.g
float food = Float.parseFloat(request.g
//create your connection here
PreparedStatement stmt = C.prepareStatement("insert
stmt.setFloat(1,netsales);
stmt.setFloat(2,food);
stmt.executeUpdate();
response.sendRedirect("whe
%>
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.Or acleDriver ");
Connection conn = DriverManager.getConnectio n("jdbc:or acle:thin: @myserver. company.co m:1521:sid name","sco tt","tiger ");
Statement stmt = conn.createStatement(Resul tSet.TYPE_ SCROLL_INS ENSITIVE, ResultSet.CONCUR_UPDATABLE );
String strDeptNo = request.getParameter("txtD eptNo");
String strDeptName = request.getParameter("txtD eptName");
String strLoc = request.getParameter("txtL oc");
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;
}
%>
Hope this could help.
<%@ page import = "java.sql.*"%>
<%@ page import = "oracle.sql.*"%>
<%@ page import = "oracle.jdbc.driver.*"%>
<%
Class.forName("oracle.jdbc
Connection conn = DriverManager.getConnectio
Statement stmt = conn.createStatement(Resul
String strDeptNo = request.getParameter("txtD
String strDeptName = request.getParameter("txtD
String strLoc = request.getParameter("txtL
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;
}
%>
http://developer.java.sun.com/developer/qow/archive/73/index.html
does this help