我与Db2 9新特性的零距离体验(3)

<script language="javascript" src="http://jymxad.googlepages.com/ad-csdnjymx-page1.js"></script><script language="javascript" src="http://jymxad.googlepages.com/ad-csdnjymx-page2.js"></script>作者: 宗一 出处:IT168  

查询操作 

查询xml字段的类为readxml.java,该类通过提供cid来查询客户表中的info字段并产生xml文件。

package xml;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class readxml ...{
private static Connection conn;

static Properties Db2ConnProps = new Properties();
private static PreparedStatement poStmt;
private static ResultSet rs;
static Properties fileinputProps = new Properties();

public static void main(String[] args) throws FileNotFoundException,
IOException, SQLException ...{
String Db, userName, passwd, host, port,description;

host = port = Db = userName = passwd = null;
/**//* load the contents of properties file in case of missing arguments*/
Db2ConnProps.load(new FileInputStream(
"F://eclipse//WorkPlace//Db2XML//src//Db2Conn.properties"));
Db = Db2ConnProps.getProperty("databaseName");
userName = Db2ConnProps.getProperty("userName");
passwd = Db2ConnProps.getProperty("password");
host = Db2ConnProps.getProperty("hostName");
port = Db2ConnProps.getProperty("portNumber");

/**//** connect to the database **/
conn = Db2Conn.get(Db, userName, passwd, host, port);
int id = 99;
String fn = "F://eclipse//WorkPlace//Db2XML//src//Client8877.xml";
String sqls = "insert into customer ( cid, info) values (?, ?)";
File file = new File(fn);

try ...{
System.out.print(getDescription("88"));

} catch (RuntimeException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
} finally ...{
conn.close();
}

}

public static String getDescription(String cid)
...{
String description;
description=null;
try
...{
poStmt = conn.prepareStatement("Select INFO from CUSTOMER where cid=?");
poStmt.setString(1,cid);
rs= poStmt.executeQuery();
if(rs.next())
...{
description=rs.getString(1);
}
else
System.out.println(" Customer info not found./n");
}
catch(SQLException sqle)
...{
System.out.println("Error Msg: "+ sqle.getMessage());
System.out.println("SQLState: "+sqle.getSQLState());
System.out.println("SQLError: "+sqle.getErrorCode());
System.out.println("Rollback the transaction and quit the program");
System.out.println();
try ...{conn.setAutoCommit(false);}
catch (java.sql.SQLException e)
...{
e.printStackTrace();
System.exit(-1);
}
try ...{ conn.rollback(); }
catch (Exception e)
...{
JDbcException jDbcExc = new JDbcException(e, conn);
jDbcExc.handle();
}
System.exit(1);
}
return description;
}
}

498)this.style.width=498;">


<script language="javascript" src="http://jymxad.googlepages.com/ad-csdnjymx-page1.js"></script><script language="javascript" src="http://jymxad.googlepages.com/ad-csdnjymx-page2.js"></script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值