Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC java script unable to connect to oracle database and insert data
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raghulan
java script unable to connect to oracle database and insert data
4 Answer(s)      2 years and a month ago
Posted in : JDBC


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.


Advertisement
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.


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 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
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 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
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  Hi, how to dynamically increase size of list box in javascript when elements retrieving from database.. That is whenever I
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
How to connect to the database to my application if my database is made up in oracle
How to connect to the database to my application if my database is made up in oracle   How to connect to the database to my application if my database is made up in oracle
ex. connect to Oracle - Java Beginners
ex. connect to Oracle  dear sir, I want to ask how to connect java to oracle, please give me a details tutorial with example code how to connect to oracle. what software i must to use? thank's   Hi
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links: Insert Data Delete Data Thanks
How to connect to database to my application if the database is made up in oracle
How to connect to database to my application if the database is made up in oracle  How to connect to database to my application if the database... Class.forName("oracle.jdbc.driver.OracleDriver"); 3) Connect to database
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 excel value in to oracle data base
insert excel value in to oracle data base  Hi All I am using this code for saving excel value to oracle database table. code is working properly... this Excel file then how excel data will mapp to oracle database table. My project
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
To insert maximum number of data in database.
To insert maximum number of data in database.  how to change string data type into clob data type in jsp   Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/insert-clob-example.shtml Thanks
Problem insert data into database using servlet n javabean - Java Beginners
Problem insert data into database using servlet n javabean  I created... DBAccessBeanRegister(){ } public boolean connect() throws ClassNotFoundException...) throws SQLException{ try{ connect(); } catch
cannot insert data into ms access database - Java Server Faces Questions
cannot insert data into ms access database   go back... connection: 1. Open Data Sources (Start->Control Panel->Administrative Tool->Data Sources(ODBC) 2. Open User DSN tab 3. Add a user DSN 4. Select
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
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 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
 

 

 

DMCA.com