permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes sql_handle_env failed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "sql_handle_env failed" Watch "sql_handle_env failed" New topic

sql_handle_env failed

javed iqbal

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;


conn=DriverManager.getConnection("jdbc dbc:newdsn","scott","tiger");
rs=stmt.executeQuery("select * from emp");

System.out.println(" "+rs.getInt(0)+" "+rs.getString(1));

catch(Exception e)


my dsn name is:newdsn.

please help me to get out of this
Jan Cumps

Joined: Dec 20, 2006
Posts: 2562

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
I agree. Here's the link:
subject: sql_handle_env failed
It's not a secret anymore!