aspose file tools*
The moose likes JDBC and the fly likes error :SQLException caught:Io exception: Got minus one from a read call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "error :SQLException caught:Io exception: Got minus one from a read call " Watch "error :SQLException caught:Io exception: Got minus one from a read call " New topic
Author

error :SQLException caught:Io exception: Got minus one from a read call

devaki hanumante
Greenhorn

Joined: Jan 18, 2009
Posts: 13
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 = "jdbcracle: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
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

Are you able to connect to 10g from sql prompt? What is port no 8081 here, is the port number of db service?


Swastik
devaki hanumante
Greenhorn

Joined: Jan 18, 2009
Posts: 13
Yes.I can login to 10g from the sql prompt.
8081 is the db port no.The home page of 10g is opening correctly.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

Is it connecting using jdbc-odbc bridge? If it connects might have got something to do with the driver.
devaki hanumante
Greenhorn

Joined: Jan 18, 2009
Posts: 13
I tried using the tomcat server
it is giving the following output

null
Couldn't Load database driver: oracle.jdbc.driver.OracleDriver

So I thik there is a problem with the driver.Do you need to set any environment variables to make the driver work.If yes,what are those
Thanks
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

have you copied ojdbc14.jar or ojdbc14_g.jar to WEB-INF\lib of your application folder while testing from tomcat?
devaki hanumante
Greenhorn

Joined: Jan 18, 2009
Posts: 13
yes i did
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

you still got the same error oracle.jdbc.driver.OracleDriver?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

Whats your jdk version?
devaki hanumante
Greenhorn

Joined: Jan 18, 2009
Posts: 13
I have jdk 1.5
I had copied the jar files in lib in eclipse
then it gave me the null
SQLException caught:Io exception: Got minus one from a read call error

When I copy the files to tomcat web apps it is giving me the same error
What could be the problem?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

have you tried jdbc-odbc bridge? If it connects might be some thing with driver or else might be something with network setup.
vinoth ar
Greenhorn

Joined: Jan 07, 2009
Posts: 21
hi devaki,

check the sid, you have left out that...hope that is the datasource you need to connect..


vino...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error :SQLException caught:Io exception: Got minus one from a read call