How to insert data into database table from a servlet? Help please.

From a servlet I want to insert a message with some servlet parameters into an oracle database table by writing 'insert into tablename'. How shall I write the sql statement?
[189 byte] By [anirbanchanda] at [2007-9-27 2:51:48]
# 1
Hi,In Servlet Service Method write business logic which will insert the data and other stuffs to oracle database,First create the connection and use the connection to insert the items in database in service method it self.
sbs_manian at 2007-7-4 23:13:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi,In Servlet Service Method write business logic which will insert the data and other stuffs to oracle database,First create the connection and use the connection to insert the items in database in service method it self.
sbs_manian at 2007-7-4 23:13:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Do you like sample code? See Open Source project Cameleon OSP at http://www.must.de/cameleon.html - you may start a servlet sample application there, too.
CMueller at 2007-7-4 23:13:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

simple suppose u wanned to insert user name and password into table user_info then this is a simple example .....

Best Regds

bondzoro

bondzoro@yahoo.com

import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;

public class tester extends HttpServlet {

Connection con = null;

public void init(ServletConfig sc){

super.int(sc);

Class.forName("oracle.jdbc.driver.OracleDriver");

}

public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOE

try {

con=DriverManager.getConnection("jdbc:oracle:thin:@database_URL:1521:ORA8","username","pa

String user = req.getParameter("username");

String pass = req.getParameter("pass");

PreparedStatement pst = con.prepareStatement("insert into user_info values(?,?)");

pst.setString(1,user);

pst.setString(2,pass);

pst.executeQuery();

pst.close();

con.close();

}catch(Exception _e){

_e.printStackTrace(System.err);

}

}

}

~

bondzoro at 2007-7-4 23:13:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
thanx a lot bondzoro
anirbanchanda at 2007-7-4 23:13:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
did it serve ur purpose ?Best RegdsBondzoro
bondzoro at 2007-7-4 23:13:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...