This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

help! strange error in servlet running

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic