java script unable to connect to oracle database and insert data

Ads
 

java script unable to connect to oracle database and insert data

Hello Everyone,

I am new to jsp and servers.. my first project given to me is to insert data from jsp to oracle database 8, so i create a table in oracle departments and two coloum name depaermentname and departmentid, i found this below jsp coding in rose india for sql and i changed the drivers for oracle.. when i try to run the jsp file from tomcat i get this error.. let me know what i am doing wrong.. and is there is any driver i need to download?

please help me to start my project, i am struggled in this.

insert.jsp

<%@page import="java.sql.*"%>
<%
String name=request.getParameter("department_name");
String address=request.getParameter("department_id");
Class.forName("oracle.jdbc.driver.OracleDriver")
           con=DriverManager.getConnection("jdbc:oracle:thin://172.25.50.247:1521/knits", "ADMIN", "ADMIN");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into departments(department_name,department_id) values('"+department_name+"','"+department_id+"')");
           out.println("Data is inserted successfully");
%>

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 5 in the jsp file: /jsp/insert.jsp
Syntax error, insert ";" to complete Statement
2: <%
3: String name=request.getParameter("department_name");
4: String address=request.getParameter("department_id");
5: Class.forName("oracle.jdbc.driver.OracleDriver")
6:            con=DriverManager.getConnection("jdbc:oracle:thin://localhost:1521/knits", "ADMIN", "ADMIN");
7:            Statement st=con.createStatement();
8:            int i=st.executeUpdate("insert into departments(department_name,department_id) values('"+department_name+"','"+department_id+"')");


An error occurred at line: 6 in the jsp file: /jsp/insert.jsp
con cannot be resolved to a variable
3: String name=request.getParameter("department_name");
4: String address=request.getParameter("department_id");
5: Class.forName("oracle.jdbc.driver.OracleDriver")
6:            con=DriverManager.getConnection("jdbc:oracle:thin://localhost:1521/knits", "ADMIN", "ADMIN");
7:            Statement st=con.createStatement();
8:            int i=st.executeUpdate("insert into departments(department_name,department_id) values('"+department_name+"','"+department_id+"')");
9:            out.println("Data is inserted successfully");


An error occurred at line: 7 in the jsp file: /jsp/insert.jsp
con cannot be resolved
4: String address=request.getParameter("department_id");
5: Class.forName("oracle.jdbc.driver.OracleDriver")
6:            con=DriverManager.getConnection("jdbc:oracle:thin://localhost:1521/knits", "ADMIN", "ADMIN");
7:            Statement st=con.createStatement();
8:            int i=st.executeUpdate("insert into departments(department_name,department_id) values('"+department_name+"','"+department_id+"')");
9:            out.println("Data is inserted successfully");
10: %>


An error occurred at line: 8 in the jsp file: /jsp/insert.jsp
department_name cannot be resolved to a variable
5: Class.forName("oracle.jdbc.driver.OracleDriver")
6:            con=DriverManager.getConnection("jdbc:oracle:thin://localhost:1521/knits", "ADMIN", "ADMIN");
7:            Statement st=con.createStatement();
8:            int i=st.executeUpdate("insert into departments(department_name,department_id) values('"+department_name+"','"+department_id+"')");
9:            out.println("Data is inserted successfully");
10: %>
11: 


An error occurred at line: 8 in the jsp file: /jsp/insert.jsp
department_id cannot be resolved to a variable
5: Class.forName("oracle.jdbc.driver.OracleDriver")
6:            con=DriverManager.getConnection("jdbc:oracle:thin://localhost:1521/knits", "ADMIN", "ADMIN");
7:            Statement st=con.createStatement();
8:            int i=st.executeUpdate("insert into departments(department_name,department_id) values('"+department_name+"','"+department_id+"')");
9:            out.println("Data is inserted successfully");
10: %>
11: 


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

Another error

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:161)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

org.apache.jasper.JasperException: Unable to load class for JSP
    org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:630)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:149)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.ClassNotFoundException: org.apache.jsp.jsp.insert_jsp
    java.net.URLClassLoader$1.run(Unknown Source)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(Unknown Source)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
    org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:628)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:149)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

View Answers

September 13, 2012 at 1:33 PM

Post your code. The error lies in your code. It seems that you haven't imported the package which is needed or having some syntax error. So overall, the problem is in your code. So send it.


September 14, 2012 at 10:10 AM

Thanks for your reply.. the coding is all follows

This is my Html coding

<html>
<form method="post" action="http://localhost:8080/examples/jsp/insert.jsp">
<table>
<tr><td>Department_Name:</td><td><input type="text" name="Department_Name"></td></tr>
<tr><td>Department_ID:</td><td><input type="text" name="Department_ID"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

This is my jsp code

<%@page import="java.sql.*"%> <% String name=request.getParameter("department_name"); String address=request.getParameter("department_id");

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

con=DriverManager.getConnection("jdbc:oracle:thin://172.25.50.247:1521/knits", "ADMIN", "ADMIN");

Statement st=con.createStatement();

int i=st.executeUpdate("insert into departments(departmentname,departmentid) values('"+departmentname+"','"+departmentid+"')"); out.println("Data is inserted successfully"); %>


September 14, 2012 at 3:37 PM

We have modified your insert.jsp file. It was having some errors. Your html file is ok. insert.jsp:

    <%@page import="java.sql.*"%> 
    <%
    String name=request.getParameter("Department_Name");
    String id=request.getParameter("Department_ID");

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

    Connection con=DriverManager.getConnection("jdbc:oracle:thin://172.25.50.247:1521/knits", "ADMIN", "ADMIN");

    Statement st=con.createStatement();

    int i=st.executeUpdate("insert into departments(departmentname,departmentid) values('"+name+"','"+id+"')");
    out.println("Data is inserted successfully");
    %>

September 15, 2012 at 10:43 AM

Thanks for your reply and codings.. when i try to compile and run the insert.jsp in jdeveloper i got the below error.. and still i struck here..i am using oracle 10g and my database is 8i which i need to conect.. and also i post the error that i got from tomcat now.. what i need to do..

**Error from Jdeveloper**

500 Internal Server Error
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:286)   at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:327)   at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:433)    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:150)  at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31)  at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:571)   at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at _23._jspService(23.jsp:9)    [/23.jsp]   at com.orionserver[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].http.OrionHttpJspPage.service(OrionHttpJspPage.java:57)  at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:350) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)   at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)    at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:663)  at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830)  at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:285) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:126) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)  at java.lang.Thread.run(Thread.java:534)

**Error from Tomcat**

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/rose/insert.jsp at line 8

5: 
6: Class.forName("oracle.jdbc.driver.OracleDriver");
7: 
8: Connection con=DriverManager.getConnection("jdbc:oracle:thin://172.25.50.247:1521/knits", "ADMIN", "ADMIN");
9: 
10: Statement st=con.createStatement();
11: 


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

javax.servlet.ServletException: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
    org.apache.jsp.jsp.rose.insert_jsp._jspService(insert_jsp.java:75)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:257)
    oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:389)
    oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:454)
    oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802)
    java.sql.DriverManager.getConnection(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    org.apache.jsp.jsp.rose.insert_jsp._jspService(insert_jsp.java:63)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

Ads









Related Tutorials/Questions & Answers:
java script unable to connect to oracle database and insert data
java script unable to connect to oracle database and insert data  ... is to insert data from jsp to oracle database 8, so i create a table in oracle... jsp coding in rose india for sql and i changed the drivers for oracle.. when i try
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data.... If I use it also, unable to connect to backend oracle database. Let me... properties file JNDI_NAME=java:com/env/Oracle/jndi db.login= db.password
Advertisements
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... created. 6) Restart your compiler and compile your java code. For Inserting Data
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... Driver Manager] Data source name not fou nd and no default driver specified
using ajax i want to insert data into oracle database
using ajax i want to insert data into oracle database  i would like to insert/update/select/delete from jsp to oracle database using ajax? please send a code for this iam using oracl database thank you
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database... be inserted into oracle database.. please help me sir...   hi friend..., in these examples MySQL is used as database system if you want to use the Oracle
Oracle Database - Insert System Time
Oracle Database - Insert System Time  Hi I want to insert only system time dynamically using a statement but not a prepared statement into Oracle Database please suggest me any code
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
procedure for inserting data into oracle database as bind variable and same...callable statement,stored procedure for insert data and also for update data into oracle database using jsp  iam a fresher newbie to softparsing i
unable to get datas from oracle database
unable to get datas from oracle database  Dear Sir, I am again struck in my project.. i want to display data from oracle database but i get...("jdbc:oracle:thin:@//172.25.50.247:1521/knits", "ADMIN", "ADMIN"); ps
database is connected but not insert the data
database is connected but not insert the data  hi, i am getting connected to database.Retrive the data also but cannot insert the data into database... <%@page language="java" import="java.sql.*" import
insert data into database
insert data into database  hi,thanks for reply just i am doing... and studentmaster is the database table name. i am using same details. Now give the data into the jsp page that data stored into the database.Here the error
insert user session into other oracle database table
insert user session into other oracle database table   hello i am a doing my project in jsp-servlet. i have doubt that when a user login to his... table. with user id i also want to insert date and current time in to database
insert data into database
insert data into database  type Exception report message...)Go to the start->Control Panel->Administrative Tools-> data sources. 2... selecting the driver, click finish button. 4)Then give Data Source Name
java with Oracle Database
java with Oracle Database  Hello I have been encountering a problem regarding creating a table with Oracle.When i am creating new table in the Database using Oracle , it is giving error saying an errror occured incursive sql
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
Java Connection to Oracle database
Java Connection to Oracle database  HI I am ubable to connnect jdbc to Oracle database.i had gone to control panel >>Administrative tool>>>Data source,in that forDNS name i typed Oracle and in TNS i culdn't
JDBC Video Tutorial- How to insert data into MySQL database table?
are the steps to insert into database: Connect to MySQL Database using JDBC...JDBC Video tutorial example for inserting data into MySQL database JDBC... and in this video I have explained the steps of write code to insert the data
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle... Panel>>Administrative Tools>>Data Sources in that i selected Oracle... just typed DNS as Oracle and for TNS i clicked on the list of TNS. But it has
About connection database oracle to java
About connection database oracle to java  **Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... to control Panel>>Administrative Tools>>Data Sources in that i selected
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... to control Panel>>Administrative Tools>>Data Sources in that i selected
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... to control Panel>>Administrative Tools>>Data Sources in that i selected
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle... Panel>>Administrative Tools>>Data Sources in that i selected Oracle... just typed DNS as Oracle and for TNS i clicked on the list of TNS .But it has
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
insert data in the database using checkbox
insert data in the database using checkbox  i am fetching data from the database using servlet on the jsp page and there is checkbox corresponding... should i insert only checked data into database on submission.   We

Ads