how add data in database through jsp

[nobr]hi master sir i am using netbeans 5.5

i use this code for show data in jsp page

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

<%--

The taglib directive below imports the JSTL library. If you uncomment it,

you must also add the JSTL library to the project. The Add Library... action

on Libraries node in Projects view can be used to add the JSTL 1.1 library.

--%>

<%--

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<%@ page import="java.sql.*,java.util.*" %>

<%@ page import="javax.sql.DataSource" %>

<%@ page import="javax.naming.Context" %>

<%@ page import="javax.naming.InitialContext"%>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<h1>JSP Page</h1>

<table><tr><td>test fahim</td></tr>

<% Context initContext = new InitialContext();

Context envContext = (Context)initContext.lookup("java:/comp/env");

DataSource ds = (DataSource)envContext.lookup("jdbc/oracle");

Connection conn = ds.getConnection();

Statement stmt = conn.createStatement ();

ResultSet rset = stmt.executeQuery ("SELECT accid FROM accbal");

while (rset.next ()) {

%>

<tr><td> <% out.println(rset.getString ("accid")); %> </td></tr>

<% } %>

</table>

<h1>JSP***|||||||||||||||||||||||**** Page</h1>

<h1>JSP*************** Page</h1>


JavaServer Faces Welcome Page

<%--

This example uses JSTL, uncomment the taglib directive above.

To test, display the page like this: index.jsp?sayHello=true&name=Murphy

--%>

<%--

<c:if test="${param.sayHello}">

<!-- Let's welcome the user ${param.name} -->

Hello ${param.name}!

</c:if>

--%>

</body>

</html>

but sir how i insert data in to database please send me code

thank's

aamir[/nobr]

[2476 byte] By [mfa786a] at [2007-11-27 0:26:39]
# 1

hi fahim,

There are many ways to add data into the database, the simplest way for you would be change the tmt.executeQuery ("SELECT accid FROM accbal");

to

tmt.executeQuery ("insert into table values('exmaple',142)");

You can also make use of Prepared Statement which will be more flexible.. In this case you create a Object of PreparedStatement and use the setString methods to set values and finally to update the database use the executeUpdate method

Hope this solves your problem, Regards,

-- Abdel Olakara

http://olakara.googlepages.com

Olakaraa at 2007-7-11 22:25:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...