aton's blog

on the way...

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  8 随笔 :: 0 文章 :: 11 评论 :: 0 Trackbacks
public class OracleDataBaseReader {
    
private final String oracleDriverName = "oracle.jdbc.driver.OracleDriver";
    //IP,端口号,数据库名
    
private final String oracleUrlToConnect ="jdbc:oracle:thin:@192.168.132.27:1522:olydb";
    
private Connection myConnection = null;

    
public OracleDataBaseReader()
    {
        
try
        {
            Class.forName(oracleDriverName);
        }
catch(ClassNotFoundException ex)
        {
            System.out.println(getErrorMessage(ex,
"The Driver loaded error,please contact to your Software Designer!").toString());
        }
    }
    
    
public StringBuffer getErrorMessage(Exception ex,String alarmMessage)
    {
        StringBuffer errorStringBuffer 
= new StringBuffer();
        errorStringBuffer.append(alarmMessage);
        errorStringBuffer.append(ex.getMessage());
        
return errorStringBuffer;
    }
   

    
public Connection getConnection()
    {
        
try
        {
            //用户名,密码
            
this.myConnection = DriverManager.getConnection(oracleUrlToConnect,"username","password");
            
        }
catch(Exception ex)
        {
            System.out.println(getErrorMessage(ex,
"Can not get connection,please contact to your Software Designer!").toString());
        }
        
return this.myConnection;
    }

    //获取结果,写入文件
    
public void getData(){
        
try
        {
            Connection myConnection 
= getConnection();  
            PreparedStatement myPreparedStatement 
= myConnection.prepareStatement("select * from beijing2008_0729.T_GL_X01");
            ResultSet myResultSet 
= myPreparedStatement.executeQuery();  
            FileWriter fw 
= null;      
            fw 
= new FileWriter("E:\\olympics\\T_GL_X01.txt");
            
int i = 0;
            
while(myResultSet.next())
            {
                System.out.println(i
++);
                StringBuffer myStringBuffer 
= new StringBuffer();
                myStringBuffer.append(myResultSet.getString(
"REGISRATION_NUMBER")+"\t");
                myStringBuffer.append(myResultSet.getString(
"DISCIPLINE")+"\t");
                myStringBuffer.append(myResultSet.getString(
"GENDER")+"\t");
                myStringBuffer.append(myResultSet.getString(
"EVENT")+"\t");
                myStringBuffer.append(myResultSet.getString(
"PHASE")+"\t");
                myStringBuffer.append(myResultSet.getString(
"UNIT")+"\t");
                myStringBuffer.append(myResultSet.getInt(
"VERSION")+"\t");
                myStringBuffer.append(myResultSet.getInt(
"CORRECTION")+"\t");
                myStringBuffer.append(myResultSet.getString(
"MESSAGE_TIME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"FAMILY_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"GIVEN_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"DOB")+"\t");
                myStringBuffer.append(myResultSet.getString(
"WNPA_GIVEN_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"WNPA_FAMILY_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"TV_SHORT_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"TV_LONG_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"INITIAL_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"REPORTING_NAME")+"\t");
                myStringBuffer.append(myResultSet.getString(
"GENDER_ID")+"\t");
                myStringBuffer.append(myResultSet.getString(
"COUNTRY_OF_BIRTH")+"\t");
                myStringBuffer.append(myResultSet.getString(
"COUNTRY_OF_RESIDENCE")+"\t");
                myStringBuffer.append(myResultSet.getString(
"HEIGHT")+"\t");
                myStringBuffer.append(myResultSet.getString(
"WEIGHT")+"\t");
                myStringBuffer.append(myResultSet.getString(
"NATIONALITY")+"\t");
                myStringBuffer.append(myResultSet.getString(
"ORGANIZATION_ID")+"\t");
                myStringBuffer.append(myResultSet.getString(
"REGISTRATION_STATUS")+"\n");
                System.out.print(myStringBuffer);
                fw.write(myStringBuffer.toString());
            }
            fw.close();
        }
catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}
posted on 2008-08-11 14:37 aton 阅读(177) 评论(0)  编辑  收藏 所属分类: 代码库

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


网站导航: