• 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

Oracle and Servlet JDBC Connection problems

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the help with my database MS Access Connection.............
But right now as type-4 driver in Oracle is working so I switched back to it......

Through this driver I could use a direct JDBC program but when I use such a code inside a servlet I get errors again......
Its a simple code where I print table after username and password matched....

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import javax.sql.*;


public class ServletDemo extends HttpServlet
{

public void init(ServletConfig sc) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=null;
try{

con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott" , "james1");
}
catch(Exception exp){
System.out.println("exp : "+exp.getMessage());
}
}
catch(Exception x){
System.out.println( "Unable to load the driver class!" );
System.out.println(x.getMessage());
}
}
public void service (HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
String un=req.getParameter("uname");
String pwd=req.getParameter("pwd");
if (un.equals("rahul") && pwd.equals("rahul"))
{
pw.println("Success");
Statement st=con.createStatement();
ResultSet rs=null;
st.executeQuery("select * from student");
rs=st.getResultSet();
if (rs != null)
while ( rs.next() )
{
System.out.println( rs.getString(1)+" "+ rs.getString(2)+" "+rs.getString(3));

}
st.close();
con.close();
}


else
{
pw.println("Login Failed");
pw.println("<a href='index.html'> Go Back</a>");
}
pw.close();
}
}


Though JDBC and Servlets are working independently when I want to use them combined I get error like:
Error 1: Cannot find symbol
symbol: Class Connection

Error 2: Cannot find symbol
symbol: Class DriverManager

Error 3: Cannot find symbol
symbol: Class Statement

Error 4: Cannot find symbol
symbol: variable con

Error 5: Cannot find symbol
symbol: Class ResultSet

I also set ojdbc14.jar as classpath.
I use Windows 7 and server is tomcat 5.5. I use Oracle 11g
Thank you
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your ojdbc14.jar present within WEB-INF/lib folder of your servlet?
 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

For the Connection ,Statement and ResultSet you need to import java.sql.*.

Declare Connection ,Statement and ResultSet objects globally..
outside init()..
jst declare and initialize to null.then you won't get the errors.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Madhan Sundararajan Devaki wrote:Is your ojdbc14.jar present within WEB-INF/lib folder of your servlet?






Thanks Madhan .. you solve my problem...
 
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic