当前位置: 技术问答>java相关
一个简单的问题,大虾们快来帮帮忙啊!
来源: 互联网 发布时间:2015-04-29
本文导语: 用java怎样才能读取excel表中的数据!希望能给出源码! | http://www.javaworld.com/javaworld/javaqa/2001-06/04-qa-0629-excel.html#resources 可以到这看看! import java.sql.Connection; import java.sql.Statement; import java.sql.Resu...
用java怎样才能读取excel表中的数据!希望能给出源码!
|
http://www.javaworld.com/javaworld/javaqa/2001-06/04-qa-0629-excel.html#resources
可以到这看看!
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
public class ExcelReader
{
public static void main( String [] args )
{
Connection c = null;
Statement stmnt = null;
try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:qa-list", "", "" );
stmnt = c.createStatement();
String query = "select URL from [qas$] where Month='March' and Year=2000;";
ResultSet rs = stmnt.executeQuery( query );
System.out.println( "Found the following URLs for March 2000:" );
while( rs.next() )
{
System.out.println( rs.getString( "URL" ) );
}
}
catch( Exception e )
{
System.err.println( e );
}
finally
{
try
{
stmnt.close();
c.close();
}
catch( Exception e )
{
System.err.println( e );
}
}
}
}
可以到这看看!
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
public class ExcelReader
{
public static void main( String [] args )
{
Connection c = null;
Statement stmnt = null;
try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:qa-list", "", "" );
stmnt = c.createStatement();
String query = "select URL from [qas$] where Month='March' and Year=2000;";
ResultSet rs = stmnt.executeQuery( query );
System.out.println( "Found the following URLs for March 2000:" );
while( rs.next() )
{
System.out.println( rs.getString( "URL" ) );
}
}
catch( Exception e )
{
System.err.println( e );
}
finally
{
try
{
stmnt.close();
c.close();
}
catch( Exception e )
{
System.err.println( e );
}
}
}
}