Meaningless Drivel is fun!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 2491
    
    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
 
Don't get me started about those stupid light bulbs.
 
subject: sql_handle_env failed
 
Similar Threads
Problem in getting the data from DB using servlets
Invalid Descriptor Index
Help for Access-JDBC
Accessing Connection pool
Problem in usebean