How to Insert/Save in Oracle 11g DB

How to Insert/Save in Oracle 11g DB

In this Video I m telling you about how to insert or Save , user Data in Oracle Database

Mysql insert/Save Video Link : Coming Soon
MS Access insert/Save Video Link : Coming Soon

All Source is Below

name - register.html

<html>
<head>
<title>registration form</title>
</head>
<h2 ALIGN="CENTER">Student Registration form</h2>
<form action="/examples/stregistration"  method="post">
<table border="0" align="center">
<tbody>
<tr>
<td><label for="rolln0">Rollno: </label></td>
<td><input id="rollno" maxlength="50" name="rollno" type="text" /></td>
</tr>
<tr>
<td><label for="name">Name: </label></td>
<td><input id="name" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="email">Email_Address:</label></td>
<td><input id="email" maxlength="50" name="email" type="text" /></td>
</tr>
<tr>
<td align="right"><input name="Submit" type="Submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>

</html>
name stregistration.java
import java.io.IOException;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class stregistration
  extends HttpServlet
{
  static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
  static final String DB_URL = "jdbc:oracle:thin:@localhost:1521:XE";
  static final String USER = "system";
  static final String PASS = "system";

  public void doPost(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws IOException, ServletException
  {
    String str1 = paramHttpServletRequest.getParameter("rollno");
    String str2 = paramHttpServletRequest.getParameter("name");
    String str3 = paramHttpServletRequest.getParameter("email");

    Connection localConnection = null;
    Statement localStatement = null;
    try
    {
      Class.forName("oracle.jdbc.driver.OracleDriver");

      localConnection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "system");

      System.out.println("Creating statement...");
      if (localConnection == null) {
        System.out.println("Connection failed");
      }
      localStatement = localConnection.createStatement();
        String str10 = "Insert  into student(roll,name,email) values('" + str1 + "','" + str2 + "','" + str3 + "')";
        System.out.println("Statement executed " + str10);
        localStatement.executeUpdate(str10);
paramHttpServletResponse.sendRedirect("http://localhost:8089/examples/successfullydone.html");

      }

    catch (SQLException localSQLException)
    {
      localSQLException.printStackTrace();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
}

name successfullydone.html
<html>
<body>
<font size="18" color="red">SuccessFully Done</font>

<a href="http://localhost:8089/examples/view.jsp" target="_blank">View Database</a>

<a href="http://localhost:8089/examples/register.html">BACK TO HOME</a>
</body>
</html>
name view.jsp
<html>
<head>
<style type="text/css">
table {
		width: 100%;
		border-collapse: collapse;
	}

/* Zebra striping */
	tr:nth-of-type(odd) {
		background: #eee;
	}

th {
		background: #333;
		color: white;
		font-weight: bold;
	}

	td, th {
		padding: 6px;
		border: 1px solid #ccc;
		text-align: left;
	}
</style>

</head>

 <body background="images/bgnoise_lg.png">
<h1><center><ax>Student Record</ax> </center></h1>
<table>
<tr>
<th>Roll</th>
<th>Name</th>
<th>Email</th>
</tr>
</head>
<body background="bgnoise_lg.png">

<%@ page import="java.sql.*" %>
<%@ page import ="tybca.*" %>
<form  method="POST">

<%  String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";   String DB_URL = "jdbc:oracle:thin:@localhost:1521:XE"; String USER = "system"; String PASS = "system";    Connection conn = null;    Statement stmt = null; ResultSet rs = null; Class.forName(JDBC_DRIVER); conn =DriverManager.getConnection(DB_URL,USER,PASS); stmt=conn.createStatement(); String sql="select * from student"; System.out.println("Created Statement"+sql); rs=stmt.executeQuery(sql); //rs.close(); //stmt.close(); //conn.close(); while(rs.next()) { %>
<tr>
<td>
<%= rs.getInt(1) %></td>
<td>
<%= rs.getString(2) %></td>
<td>
<%= rs.getString(3) %></td>
</tr>
<% } %>
</form>

<a href="http://localhost:8089/examples/register.html">BACK TO HOME</a>
</body>
</html>

Keywords
how to insert values into table in mysql using java
how to insert values into table in oracle using java
insert query in java using prepared statement
inserting data into database using java netbeans
how to insert values into table in mysql using java in eclipse
inserting data into mysql database using java
how to store data in database using java
java code for inserting data into database
java jdbc insert example

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s