Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Insert Data to Qracle DB fails (query works)?

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Insert Data to Qracle DB fails (query works)?

    Hi,

    I have a simple jsp site and
    use a the "jdbcracle:thin" driver as connection to the Database.

    <%@ page contentType="text/html" language="java"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
     
    <sql:setDataSource driver="oracle.jdbc.driver.OracleDriver"
    	url="jdbc:oracle:thin:@localhost:1521:xe" user="JamesBond"
    	password="topsecret" />

    It works to query some information form the database and print it to the html page:

    <sql:query var="vehicles" sql="select * from vehicles">
    </sql:query>
     
    <c:forEach var="vehicle" begin="0" items="${vehicles.rows}">
    	<option value="${vehicle.id}"
    		<c:if test="${param.id eq vehicle.id}">selected="selected"</c:if>>
    		${vehicle.type} ${vehicle.name}</option>
    </c:forEach>

    But when I try to Insert something to the DB I got some errors.

    		<sql:query var="res" sql="INSERT INTO DOCKBOOK (DOCKNUMMER, CAT, DOG) VALUES (12, 11, 11);"> 
    		</sql:query>

    Exception Handler
     
     
    Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
     
    Exception Details: javax.servlet.ServletException
      javax.servlet.jsp.JspException: INSERT INTO DOCKBOOK (DOCKNUMMER, CAT, DOG) VALUES (12, 11, 11);: ORA-00911: invalid character
     
    Possible Source of Error:
      Class Name: org.apache.jasper.runtime.PageContextImpl
      File Name: PageContextImpl.java
      Method Name: doHandlePageException
      Line Number: 839
     
    Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.
     
    Stack trace:
     
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:839)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
    org.apache.jsp.jamesbond.example_jsp._jspService(example_jsp.java:197)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
    org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
    org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
    org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
    org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    java.lang.Thread.run(Thread.java:595)
    The line 839 does not exist within my code.


    Also tried alternatively:
     <%  
                Connection connection = null;
                Class.forName("oracle.jdbc.driver.OracleDriver");
                connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "JamesBond", "topsecret");
     
                Statement statement = connection.createStatement();
     
                String command = "INSERT INTO DOCK (DOCKNUMMER, PERSONAL, KAPAZITAET) VALUES (12, 11, 11);";
                statement.executeUpdate(command);
            %>

    with error:
     
    Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
     
    Exception Details: org.apache.jasper.JasperException
      Unable to compile class for JSP An error occurred at line: 263 in the jsp file: /jamesbond/example.jsp Generated servlet error: Connection cannot be resolved to a type An error occurred at line: 263 in the jsp file: /jamesbond/example.jsp Generated servlet error: DriverManager cannot be resolved An error occurred at line: 263 in the jsp file: /jamesbond/example.jsp Generated servlet error: Statement cannot be resolved to a type
     
    Possible Source of Error:
      Class Name: org.apache.jasper.compiler.DefaultErrorHandler
      File Name: DefaultErrorHandler.java
      Method Name: javacError
      Line Number: 84
     
    Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.
     
    Stack trace:
     
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
    org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
    org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
    org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
    org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    java.lang.Thread.run(Thread.java:595)
    The line 84 is the line is only HTML
    Line 263 is the opening "<%" Tag

    Does anyone see the problem?


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Insert Data to Qracle DB fails (query works)?

    Quote Originally Posted by Andeas_L View Post
    Hi,

    I have a simple jsp site and
    use a the "jdbcracle:thin" driver as connection to the Database.

    <%@ page contentType="text/html" language="java"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
     
    <sql:setDataSource driver="oracle.jdbc.driver.OracleDriver"
    	url="jdbc:oracle:thin:@localhost:1521:xe" user="JamesBond"
    	password="topsecret" />

    It works to query some information form the database and print it to the html page:

    <sql:query var="vehicles" sql="select * from vehicles">
    </sql:query>
     
    <c:forEach var="vehicle" begin="0" items="${vehicles.rows}">
    	<option value="${vehicle.id}"
    		<c:if test="${param.id eq vehicle.id}">selected="selected"</c:if>>
    		${vehicle.type} ${vehicle.name}</option>
    </c:forEach>

    But when I try to Insert something to the DB I got some errors.

    		<sql:query var="res" sql="INSERT INTO DOCKBOOK (DOCKNUMMER, CAT, DOG) VALUES (12, 11, 11);"> 
    		</sql:query>

    Exception Handler
     
     
    Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
     
    Exception Details: javax.servlet.ServletException
      javax.servlet.jsp.JspException: INSERT INTO DOCKBOOK (DOCKNUMMER, CAT, DOG) VALUES (12, 11, 11);: ORA-00911: invalid character
     
    Possible Source of Error:
      Class Name: org.apache.jasper.runtime.PageContextImpl
      File Name: PageContextImpl.java
      Method Name: doHandlePageException
      Line Number: 839
     
    Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.
     
    Stack trace:
     
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:839)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
    org.apache.jsp.jamesbond.example_jsp._jspService(example_jsp.java:197)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
    org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
    org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
    org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
    org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    java.lang.Thread.run(Thread.java:595)
    The line 839 does not exist within my code.


    Also tried alternatively:
     <%  
                Connection connection = null;
                Class.forName("oracle.jdbc.driver.OracleDriver");
                connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "JamesBond", "topsecret");
     
                Statement statement = connection.createStatement();
     
                String command = "INSERT INTO DOCK (DOCKNUMMER, PERSONAL, KAPAZITAET) VALUES (12, 11, 11);";
                statement.executeUpdate(command);
            %>

    with error:
     
    Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
     
    Exception Details: org.apache.jasper.JasperException
      Unable to compile class for JSP An error occurred at line: 263 in the jsp file: /jamesbond/example.jsp Generated servlet error: Connection cannot be resolved to a type An error occurred at line: 263 in the jsp file: /jamesbond/example.jsp Generated servlet error: DriverManager cannot be resolved An error occurred at line: 263 in the jsp file: /jamesbond/example.jsp Generated servlet error: Statement cannot be resolved to a type
     
    Possible Source of Error:
      Class Name: org.apache.jasper.compiler.DefaultErrorHandler
      File Name: DefaultErrorHandler.java
      Method Name: javacError
      Line Number: 84
     
    Source not available. Information regarding the location of the exception can be identified using the exception stack trace below.
     
    Stack trace:
     
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
    org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
    org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
    org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
    org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    java.lang.Thread.run(Thread.java:595)
    The line 84 is the line is only HTML
    Line 263 is the opening "<%" Tag

    Does anyone see the problem?
    Yes, it can be the problem with your imports. Can you show your imports?

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Insert Data to Qracle DB fails (query works)?

    Hmm
    Only:
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.core.*" %>
    <%@ page import="java.function.*" %>

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Insert Data to Qracle DB fails (query works)?

    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    Why is this for? And are you using it to create connection?

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Insert Data to Qracle DB fails (query works)?

    Quote Originally Posted by Mr.777 View Post
    Why is this for? And are you using it to create connection?
    hmm yee..ss ... as taglib sql
    Using to make connection here ..
     <sql:setDataSource driver="oracle.jdbc.driver.OracleDriver"
    	url="jdbc:oracle:thin:@localhost:1521:xe" user="JamesBond"
    	password="topsecret" />
    works fine for query Info from the DB but not into the DB.

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Insert Data to Qracle DB fails (query works)?

    Hmmm... okay fine. Have you imported ojdbc14.jar in your application libraries? If not, try including this. You can download it by googling.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Insert Data to Qracle DB fails (query works)?

    For your ease, you can download it from User account | Teradata Developer Exchange

Similar Threads

  1. Replies: 3
    Last Post: September 1st, 2011, 11:49 AM
  2. Replies: 2
    Last Post: June 15th, 2011, 04:49 PM
  3. Replies: 1
    Last Post: June 11th, 2011, 06:39 AM
  4. [SOLVED] Using Java CheckBox to insert data to MSAccess Database
    By sandlucky in forum JDBC & Databases
    Replies: 1
    Last Post: May 16th, 2011, 12:43 AM
  5. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 11:15 AM