Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC Connection

Status
Not open for further replies.

tkpchary

Programmer
Joined
Oct 16, 2000
Messages
5
Location
IN
Hi All!
I am using easysoft jdbc-odbc bridge to connect to an access database. The following error is displayed.

java.sql.SQLException: Connection failed String index out of range: -33
java.lang.NullPointerException:

What might be the problem..

the code is
import java.* ;
import java.sql.* ;
public class FirstApp {
public static void main(String[] args){
System.out.println("First Program Hello World \n");
System.out.println("First1 Program1 Hello World1 \n");
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
String query = "SELECT * from Tourist_Places" ;
String url="jdbc:easysoft://hostname:8031/dsnname:limit=30";
try{
Class.forName("easysoft.sql.jobDriver");
System.out.println("Driver Loaded");
}catch( Exception e){
System.out.println(e);
}

try{
con = DriverManager.getConnection(url);
System.out.println(" Connection Successfull");
}catch( Exception e){
System.out.println("Testing:"+e);
}

try{
stmt = con.createStatement();
System.out.println(" Statement Created");
rs = stmt.executeQuery(query);
String place = rs.getString("placeName");
String desc = rs.getString("Desc");
System.out.println(place + " " + desc);
}catch( Exception e){
System.out.println(e);
}




}
}

Note : In place of hostname I used my local system IP and inplace of dsnname my database dsn.

thanks in advance.


[sig][/sig]
 
You have to direct the 'rs' object to the first row...
before doing any rs.getString()..

Otherwise... 'ResultSet' will be pointing nowhare :-)

so insert " rs.next()"
immediatly after stmt.executeQuery()

(eg)
rs = stmt.executeQuery(query);
rs.next()
String place = rs.getString(&quot;placeName&quot;); [sig]<a href=mailto:pondyprem@yahoo.com>pondyprem@yahoo.com</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top