hi
i have created the following
servlet which i want to connect to oracle 10g.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection con = null;
String driver = "oracle.jdbc.driver.OracleDriver";
String serverName ="devaki";
String portNumber = "8081";
String sid = "";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber+ ":" + sid;
String username = "system";
String password = "tiger";
PrintWriter out = response.getWriter();
//Retrieving values from HTML page
String CourseName=request.getParameter("CourseName");
String CourseId=request.getParameter("CourseId");
String CourseCapacity=request.getParameter("CourseCapacity");
String CourseDesc=request.getParameter("CourseDesc");
String CourseDuration=request.getParameter("CourseDuration");
try {
Class.forName(driver);
con = DriverManager.getConnection(url, username,password);
String sql = "insert into Course values(?,?,?,?,?)";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, CourseId);
pst.setString(2, CourseName);
pst.setString(3, CourseCapacity);
pst.setString(4, CourseDesc);
pst.setString(5, CourseDuration);
pst.executeUpdate();
pst.close();
pst.close();
con.close();
}
catch (ClassNotFoundException e){
out.println("Couldn't Load database driver: "+e.getMessage());
}
catch (SQLException e){
out.println("SQLException caught:"+e.getMessage());
}
catch (Exception e) {
out.println(e); }
finally
{
try
{
if (con!= null)
con.close();
}
catch(SQLException ignored)
{
out.println(ignored);
}
}
}
}
I am getting the error SQLException caught:Io exception: Got minus one from a read call
I think that he error is at the line con = DriverManager.getConnection(url, username,password);
My servlet is not getting connected to the database.
Is it because i also have oracle 8i installed on my machine.Do I need to uninstall it first?
I am using Eclipse Ganymede for execution of the servlet
Any help will be appreciated
Thanks