JDBC-ODBC连接sql2000数据库

JDBC-ODBC连接sql2000数据库

package connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnectionAccess {


 public static void main(String[] args) {
try{
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 Connection con=DriverManager.getConnection("jdbc:odbc:employee","","");
 Statement stmt =con.createStatement();
 ResultSet rs =stmt.executeQuery("select fname,minit from employee");
 while (rs.next()){
 System.out.print("\t fname:"+rs.getString(1));
 System.out.print("\t minit:"+rs.getString(2));
 System.out.println();
 }
 rs.close();
 stmt.close();
 con.close();
 }catch(Exception e){
 e.printStackTrace();
}
 }

}

你可能感兴趣的:(JDBC-ODBC连接sql2000数据库)