随笔-167  评论-65  文章-0  trackbacks-0

我们知道micro的sql server jdbc驱动限制了记录的回读功能,这样开发的过程会经常出现错误,所以有了opensource的jtds.jar,使用方法见下:

1,在工程的path中加入jtds.jar包

2,连接数据库的核心代码:

package bean;

import java.sql.*;



public class ConnectSqlserver {
    
    private String driverClass = "net.sourceforge.jtds.jdbc.Driver";

    private String url ="jdbc:jtds:sqlserver://localhost:1433/award";

    private String user = "test";

    private String password = "riskfitfeng";

    private Connection connection;

    public ConnectSqlserver() {
    }

    public Connection openConnection() throws SQLException {
        try {
            Class.forName(driverClass);
            connection = DriverManager.getConnection(url, user, password);        
            return connection;
        } catch (Exception e) {
            throw new SQLException(e.getMessage());
        }
    }

    public void closeConnection() {
        try {        
            if (connection != null)
                connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}

jtds.jar下载地址:

http://www.namipan.com/d/aa2da07f13f819aa9bb030cbebbfa1563257d90ed00a0800

ref:

http://www.java-tips.org/other-api-tips/jdbc/how-to-store-retrieve-image-to-from-sqlserver.html



write by feng
posted on 2009-06-02 14:10 fl1429 阅读(4857) 评论(0)  编辑  收藏 所属分类: Jsp/Servlet/Javabean

只有注册用户登录后才能发表评论。


网站导航:
 
已访问数:
free counters