//First we shound inport all necessary package
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
pubulc class Test
{
public static void main(String[] args)
{
Connection connection=null;
Statement statement=null;
try
{
class.forName("com.jdbc.odbc.JdbcOdbcDriver");
connection=DriverManager.getConnection("jdbc:odbc:hust","","");
// Get Connection , because ODBC DataSource name is "hust",
// Give password and name all are null
statement=connection.createStatement();
// Create Statement
String sql="SELECT * FROM [Sample1$]";
//Note: We suppose DataSheet name is "Sample1" and here
// the table format is "["+DataSheet Name+"$]",There is
// The difference between Excel and Access
ResultSet rs=statement.executeQuery(sql);
System.out.println("Now the Search Result is :");
while(rs.next())
{
System.out.println(rs.getString(1));
}
}
catch(Exception e)
{
System.err.println("Error Message:"+e.toString());
e.printStackTrace();
}
finally
{
try
{
statement.close();
connection.close();
}
catch(Exception e)
{
System.out.println("Close Failed!"+e);
e.printStackTrace();
}
}
}
}
Step 4: Save the File and Compile the run.
以上是基本步骤,可以根据自己的需要进行响应的处理!