Jdbc Test

package com.jxr.agent;

import com.jxr.database.SqlHelper;
import com.jxr.database.SqlParamater;
import com.jxr.database.SqlParamaterType;
import com.jxr.common.PhotoData;
import com.jxr.framework.SysSetting;

import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.List;
import java.util.ArrayList;
import java.io.Console;

/**
 * Created by hcmfys.
 * User: Administrator
 * Date: 2009-11-20
 * Time: 20:33:10
 * To change
 */
public class TestAgent extends SqlHelper {
    public TestAgent() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        super(SysSetting.SqlConnectionString, DataType.SQL, "sa", "1");
    }

    public List<PhotoData> GetPhotoList() {
        try {
            ArrayList<PhotoData> list = new ArrayList<PhotoData>();
            ResultSet rs = super.ExecuteProcedure("{call getUrl(?)} ",
                    new SqlParamater<Integer>(SqlParamaterType.INTEGER, "id", 1));                       //select * from PhotoData
            while (rs.next()) {
                PhotoData p = new PhotoData(rs);
                list.add(p);
            }

            return list;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }finally{
           super.dispose();
        }
    }

    public static void main(String[] args) {
        TestAgent test;
        try {
            test = new TestAgent();
            List<PhotoData> list = test.GetPhotoList();
            Console con = System.console();
            if (con != null)
                con.readLine();
            for (PhotoData p : list) {
                System.out.println(p.getId() + "  " + p.getUrl());
            }
        }
        catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

    }
}


--------------------------------------------------------------
package com.jxr.framework;

/**
 * Created by hcmfys
 * User: Administrator
 * Date: 2009-11-20
 * Time: 21:16:41
 *  
 */
public class SysSetting {


    public static String SqlConnectionString="jdbc:sqlserver://127.0.0.1:1433;databaseName=Test;user=sa;password=1"   ;
    public static String DbConnectionString = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=e:/javax/jxrDb.mdb";

}

你可能感兴趣的:(java,sql,jdbc,Microsoft,Access)