当前位置: 代码迷 >> SQL >> maven工程中怎么引入sql server 2008 驱动jar包
  详细解决方案

maven工程中怎么引入sql server 2008 驱动jar包

热度:38   发布时间:2016-05-05 12:23:59.0
maven工程中如何引入sql server 2008 驱动jar包
http://www.blogjava.net/bang/archive/2012/08/02/384617.html

用jTDS通过JDBC连:
<dependency>  <groupId>net.sourceforge.jtds</groupId>  <artifactId>jtds</artifactId>  <version>1.2.4</version></dependency>


public static List<String> executeQuery(String sql,String columns) {        try {            Connection conn = getConnection();            Statement st = conn.createStatement();            ResultSet set = st.executeQuery(sql);            List<String> result = new ArrayList<String>();            while (set.next()) {                String[] columnList = columns.split(",");                for(String str:columnList){                    result.add(set.getString(str));                }                            }            set.close();            st.close();            conn.close();            return result;        } catch (SQLException e) {            throw new IllegalArgumentException(e);        }    }    public static Connection getConnection() {        try {            Class.forName("net.sourceforge.jtds.jdbc.Driver");            String url = "jdbc:jtds:sqlserver://localhost:1433;DatabaseName=jdl";            String username = "sa";            String password = "";            Connection conn = DriverManager.getConnection(url, username,            password);            return conn;        } catch (Exception e) {            throw new IllegalArgumentException(e);        }    }
  相关解决方案