Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

help! strange error in servlet running

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My servlet code is like this:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.text.*;
public class JDBC4Servlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{ response.setContentType("text/html");
PrintWriter out = new PrintWriter(response.getOutputStream());
out.println("<HTML>");
out.println("<HEAD><TITLE>Table</TITLE></HEAD>");
out.println("<BODY>");
try{
//System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
Class.forName("oracle.jdbc.driver.OracleDriver");
out.println("-1");
out.flush();
out.println("0");
out.flush();
Connection con =
DriverManager.getConnection("jdbc racle:thin:@kgdev01:1521:testdb","sysadmin","kinetix");
// this line has problem
out.println("1");
out.flush();
Statement stmt = con.createStatement();
out.println("2");
.................
The file succeds to compile and then i put the servlet class file into
the websphere application server directory.
I open the browser and then test the servlet.
The error output is:
-1 0 java.lang.ArrayIndexOutOfBoundsException: 7
But if I set the incorrect username as the parameter of the
getconnection
The servlet can suceed to detect invalid user log in. The output is :
-1 0 java.sql.SQLException: ORA-01017: invalid username/password; logon
denied
This mean that the connection setting should be correct.
Anyone know how to solve this problem.
Thx for reply.
 
Victor Lam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this version is more correct
My servlet code is like this:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.text.*;
public class JDBC4Servlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{ response.setContentType("text/html");
PrintWriter out = new PrintWriter(response.getOutputStream());
out.println("<HTML>");
out.println("<HEAD><TITLE>Table</TITLE></HEAD>");
out.println("<BODY>");
try{
//System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
Class.forName("oracle.jdbc.driver.OracleDriver");
out.println("-1");
out.flush();
out.println("0");
out.flush();
Connection con =
DriverManager.getConnection("jdbc. oracle:thin:@kgdev01:1521:testdb","sysadmin","kinetix");
// this line has problem
out.println("1");
out.flush();
Statement stmt = con.createStatement();
out.println("2");
.................
The file succeds to compile and then i put the servlet class file into
the websphere application server directory.
I open the browser and then test the servlet.
The error output is:
-1 0 java.lang.ArrayIndexOutOfBoundsException: 7
But if I set the incorrect username as the parameter of the
getconnection
The servlet can suceed to detect invalid user log in. The output is :
-1 0 java.sql.SQLException: ORA-01017: invalid username/password; logon
denied
This mean that the connection setting should be correct.
Anyone know how to solve this problem.
Thx for reply.
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are entering the wrong password then you would surely not get the connection and hence the error.
but for the arrayindexoutofboundexception you should give the complete code. because i am unable to under stand the problem seeing only that part of the code. kindly present the complete code.
regards,
shekar.
 
Have you no shame? Have you no decency? Have you no tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic