小工具用法

//http://pipboy.group.iteye.com/

//how to build app as jar file:
//run build.xml

//how to use this app
//example:

import java.util.List;
import java.util.Map;

import org.apache.commons.dbcp.BasicDataSource;

import com.pipboy.util.Query;
import com.pipboy.util.QueryFactory;

public class Main {
    public static void main(String[] args){
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/hibernate");
        dataSource.setUsername("root");
        dataSource.setPassword("123");
        String sql = "select * from test where facilityid=:id and facilityname=:name";
        Query query = QueryFactory.createSQLQuery(dataSource, sql);
        query.setParameters("id", "11111");
        query.setParameters("name", "pipboy");
        query.setDebug(true);
        List<Map<String, Object>> result = query.execueteQuery();
        System.out.println(query.toString(result));
    }
}

//console result:
//{FACILITYID=11111, FACILITYNAME=pipboy, NAME=B.Chen, VALUE=admin}

//depends jar list:
//commons-collections-2.1.1.jar
//commons-dbcp-1.2.2.jar
//commons-pool-1.3.jar

//jdbc dirver depends jar:
//mysql-connector-java-5.1.6-bin.jar

你可能感兴趣的:(java,sql,mysql,Hibernate,jdbc)