자바 코드 연결 sqlserver

2105 단어 자바
다음은 Maven 의존.

        
            com.mchange
            c3p0
            0.9.5.2
        

        
            commons-dbutils
            commons-dbutils
            1.6
        
        
            com.microsoft.sqlserver
            mssql-jdbc
            6.2.0.jre8
            runtime
        

코드:
package yofc;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.beans.PropertyVetoException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class demo {
    private static QueryRunner qr = null;
    private static ComboPooledDataSource cpds = null;
    
    public static void test(){
        cpds = new ComboPooledDataSource();
        try {
            cpds.setDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
        cpds.setJdbcUrl("jdbc:sqlserver://10.111.69.111:1433;DatabaseName=test");
        cpds.setMinPoolSize(5);
        cpds.setAcquireIncrement(5);
        cpds.setMaxPoolSize(20);
        cpds.setUser("sa");
        cpds.setPassword("user");

        qr = new QueryRunner(cpds);
    }

    public static void main(String[] args) {
        test();
        try {
            String sql = "select * from test";
            List> query = qr.query(sql, new MapListHandler());
            for (int i = 0; i 

좋은 웹페이지 즐겨찾기