I have a problem in updating my Oracle Database using NetBeans.
I enter an Email Address in a form on a jsp page and redirect this page to servlet in which database code is written. When form is submitted by entering Email Address it doesn’t get stored in the database and also doesn’t print “updated” as written in the servlet code.
I have created a table in the database named “email” with a field address of type varchar(40).
Below is my servlet code:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String mail=request.getParameter("t1");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=null;
try
{
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","ankush","abcdefg");
PreparedStatement stmt=con.prepareStatement("insert into email values(?)");
stmt.setString(1,mail);
stmt.executeUpdate();
out.println("updated");
}
finally
{
con.close();
}
}
catch(SQLException e)
{
}
catch(Exception e1)
{
}
}
}
Exapnd the project node right click on librarys and add
ojdbc14_g.jar
class name is:
oracle.jdbc.driver.OracleDriver
url is
jdbc:oracle:thin:@[:<1521>]:
You can find ojdbc14_g.jar somewhere inside the installation folder of your oracle db
or try http://wiki.netbeans.org/DatabasesAndDrivers#section-DatabasesAndDrivers-OracleDriverForTheOracle10.xDatabase