Note that there are some explanatory texts on larger screens.

plurals
  1. POInserted rows is not updating in database through JDBC
    text
    copied!<p>hi am trying to insert values into SQL database using jdbc. Current code able to connect and query sql DB. am using executeupdate to insert the values .this code is not giving any errors.but values are not getting inserted into SQL DB,even though i tired commiting the code after and before executing. how can i insert values into DB???</p> <pre><code> import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import oracle.jdbc.driver.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Servlet1 extends HttpServlet { protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { String p1=request.getParameter("param1"); String p2=request.getParameter("param2"); String p3=request.getParameter("param3"); String p4=request.getParameter("param4"); String p5=request.getParameter("param5"); String sql="INSERT INTO EMPLOYEES (Id,Name,Post,Salary,Location) VALUES('" + p1 + "','" + p2 + " ','" + p3 + "','" + p4 + " ','" + p5 + " ')"; try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch(ClassNotFoundException ex) { ex.printStackTrace(); } Connection con=null; Statement stmt=null; try { con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","test","Gari!2563"); stmt=con.createStatement(); stmt.executeUpdate(sql); con.setAutoCommit(true); } catch(SQLException ex) { ex.printStackTrace(); } finally { try { if(stmt!=null) { stmt.close(); stmt=null; } } catch(SQLException ex) { ex.printStackTrace(); } try { if(con!=null) { con.close(); con=null; } } catch(SQLException ex) { ex.printStackTrace(); } } PrintWriter out = response.getWriter(); out.println("done"); } </code></pre> <p>}</p> <p>I AM USING jdk1.7 ,Oracle DB XE 11.2.0. Apache tomcat 7 eclipse juno EE edition.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload