我写了一段代码,想将excel表中的数据读出来输出到控制台,我先将excel表配置的哦数据源中。但总是报错,以下是我的代码
package com.hyxy.attendce;import java.sql.*;public class ExcelImport_odbc { private static Connection con=null;
private static PreparedStatement ps=null;
static{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//建立连接
public static Connection getConnection() throws SQLException{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=excel_import";
String username="";
String password="";
con=DriverManager.getConnection(url,username,password);
return con;
}
public static void main(String[] args) {
Connection c = null;
Statement stmnt = null;
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:salary" );
stmnt = c.createStatement();
String query = "SELECT gonghao FROM [gzjc$] ";
ResultSet rs = stmnt.executeQuery(query);
System.out.println( "记录为:" );
while( rs.next() ) {
System.out.println( rs.getString( "gonghao" ) );
}
}
catch( Exception e ) {
System.err.println( e );
}
finally {
try {
stmnt.close();
c.close();
}
catch( Exception e ) {
System.err.println( e );
}
}
}}希望各位高手帮个忙,不甚感激
package com.hyxy.attendce;import java.sql.*;public class ExcelImport_odbc { private static Connection con=null;
private static PreparedStatement ps=null;
static{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//建立连接
public static Connection getConnection() throws SQLException{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=excel_import";
String username="";
String password="";
con=DriverManager.getConnection(url,username,password);
return con;
}
public static void main(String[] args) {
Connection c = null;
Statement stmnt = null;
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:salary" );
stmnt = c.createStatement();
String query = "SELECT gonghao FROM [gzjc$] ";
ResultSet rs = stmnt.executeQuery(query);
System.out.println( "记录为:" );
while( rs.next() ) {
System.out.println( rs.getString( "gonghao" ) );
}
}
catch( Exception e ) {
System.err.println( e );
}
finally {
try {
stmnt.close();
c.close();
}
catch( Exception e ) {
System.err.println( e );
}
}
}}希望各位高手帮个忙,不甚感激
用POI 或 JXL 读数据多简单啊!