File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes sql_handle_env failed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql_handle_env failed" Watch "sql_handle_env failed" New topic
Author

sql_handle_env failed

javed iqbal
Greenhorn

Joined: Dec 30, 2007
Posts: 2
whenever I m trying to set the connection with my database i get the following error:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle
on SQL_HANDLE_ENV failed

my code is:

import java.sql.*;

public class testconnection
{



public static void main(String ar[])
{
Connection conn;
Statement stmt;
ResultSet rs;

try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc dbc:newdsn","scott","tiger");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from emp");

while(rs.next())
{
System.out.println(" "+rs.getInt(0)+" "+rs.getString(1));
}

conn.close();
}
catch(Exception e)
{
System.out.println(e);
}

}
}


my dsn name is:newdsn.

please help me to get out of this
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2499
    
    8

At what line in your code does the error occur?

You can't use rs.getInt(0). The first column in a rsultset has index 1.
(please also avoid using select * from... Use the column names instead).

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql_handle_env failed