Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

sql_handle_env failed  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2634
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!