Tuesday, May 01, 2007

Java code snippet for ODBC connections.



import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement ;

public class JDBCDemo {
public static void main( String[] args ) {
try {
// Connect to the database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// JDBC:ODBC:
String database = "jdbc:odbc:DRIVER={Microsoft Visual Foxpro Driver};SourceType=DBF;"
database+= "SourceDB=J:\\data\\;Exclusive=No;Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
// USERNAME/PASSWORD (If Needed)
Connection con = DriverManager.getConnection(database, "", "");
// Execute the SQL statement
Statement stmt = con.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * from claim");
// Loop thru all the rows
while( resultSet.next() ) {
String data = resultSet.getString( "field" );
System.out.println( data );
}
stmt.close();
}
catch( Exception e ) {
System.out.println (e.getMessage());
e.printStackTrace();
}
}
}

Comments: Post a Comment

Links to this post:

Create a Link

<< Home


Recent Posts


SCJP Study continues
Rob's Timers
Studying for the SCJP
The Easter Egg
Version Checking Class for PAD files.
Quick Test Case
PhotoCopy
Blinky
HARDWARE: Creating My own PVR for HDTV (ATSC) on a...
VFP: User interface not allowed at this time


Archives

01/01/2005 - 02/01/2005
02/01/2006 - 03/01/2006
03/01/2006 - 04/01/2006
04/01/2006 - 05/01/2006
05/01/2006 - 06/01/2006
09/01/2006 - 10/01/2006
10/01/2006 - 11/01/2006
11/01/2006 - 12/01/2006
12/01/2006 - 01/01/2007
04/01/2007 - 05/01/2007
05/01/2007 - 06/01/2007
01/01/2008 - 02/01/2008
02/01/2008 - 03/01/2008
05/01/2008 - 06/01/2008
06/01/2008 - 07/01/2008
08/01/2008 - 09/01/2008
09/01/2008 - 10/01/2008
11/01/2008 - 12/01/2008
12/01/2008 - 01/01/2009
01/01/2009 - 02/01/2009
02/01/2009 - 03/01/2009
04/01/2009 - 05/01/2009
05/01/2009 - 06/01/2009
07/01/2009 - 08/01/2009
01/01/2010 - 02/01/2010

My Software

Blinky - GBPVR Plugin
PhotoCopy - GBPVR Plugin
QTC - Quick Test Case
rBoop - Rob's Timers

Programming Links

C# Formatter
NSIS

Other Links

Damn Small Linux

Sites I Manage

Do it yourself SEO. Cheap.
Pet Supplies
Dog toy of the month club
SqueakerZ pet Deals
Geocaching Community
Hitch hiker Tracking