Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JDBC and Relational Databases
not able to connect to oracle DB
Radhakrishna Sharma Gorenta
Ranch Hand
Posts: 63
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; PrintWriter out; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection connection = null; Statement statement = null; ResultSet rs = null; response.setContentType("text/html"); out=response.getWriter(); String uname=request.getParameter("username"); String upwd=request.getParameter("password"); try { // connecting to database /*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection=DriverManager.getConnection("jdbc:odbc:rk","system","password");*/ Class.forName("oracle.jdbc.driver.OracleDriver"); connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","password"); statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM dbusers"); // displaying data while(rs.next()) { String uname2=rs.getString("username"); String upwd2=rs.getString("password"); if (uname.equals(uname2) && upwd.equals(upwd2) && uname !=null && upwd !=null) { response.sendRedirect("userLogged.jsp"); } else { response.sendRedirect("invalidLogin.jsp"); } } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if(rs != null) { rs.close(); rs = null; } if(statement != null) { statement.close(); statement = null; } if(connection != null) { connection.close(); connection = null; } } catch (Exception e) { e.printStackTrace(); } } } }
the error is wel known ClassCastException"
1.i attached the corresponding jar file ojdbc14.jar
2.no other errors, this is one particular program
Regards,
Radhakrishna
Philip Grove
Ranch Hand
Posts: 68
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I cannot see any reason for a ClassCastException, please post the complete stack trace so we can see what happens.
BTW: Catching Exception is generally a bad idea as you might hide useful information
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Problem in returning the username
To show the Error message at the login.jsp page using servlet
Help with this code!
java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).
Error in JDBC ODBC
More...