Java、XML与数据库编程实践 (三)
2008-01-05 19:22:11 来源:WEB开发网核心提示:文件DbInput.java则是真正的数据拷贝部分:import java.sql.*;public class DbInput{Connection src=null;Connection dest=null;Connection connformax=null;ConnPara srcPara;ConnPara d
文件DbInput.java则是真正的数据拷贝部分:
import java.sql.*;
public class DbInput
{
Connection src=null;
Connection dest=null;
Connection connformax=null;
ConnPara srcPara;
ConnPara destPara;
public DbInput(){}
public void dbInit()
{
DbxmlParser xmlparser=new DbXmlParser("dbs.xml");
srcPara=xmlparser.getSource();
destPara=xmlparser.getDest();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" );
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
src = DriverManager.getConnection( srcPara.getUrl(), srcPara.getUsername(),srcPara.getPassWord());
dest =DriverManager.getConnection( destPara.getUrl(), destPara.getUsername(),destPara.getPassword());
connformax= DriverManager.getConnection( destPara.getUrl(), destPara.getUsername(),destPara.getPassword());
}
//捕捉加载驱动程序异常
catch ( ClassNotFoundException cnfex ) {
System.err.PRintln( "装载 JDBC/ODBC 驱动程序失败。" );
cnfex.printStackTrace();
System.exit( 1 ); // terminate program
} catch ( SQLException ex )
{
System.err.println( "连接失败" );
ex.printStackTrace();
System.exit( 1 ); // terminate program
}
}
public void copyprodUCt()
{
Statement st=null;
ResultSet rset=null;
String sqlstr;
try {
//执行SQL语句
String query = "select * from production";
st = src.createStatement();
rset = st.executeQuery(query);
int pid,ljid,cid,ciid;
while(rset.next())
{
String pnumber=rset.getString(1);
String ljnumber=rset.getString(2);
String cnumber=rset.getString(3);
//插入到产品表
pid=getIdfromNumber("project","number",pnumber);
if(pid==0) //插入一条新记录
{
pid=getMax("project");
更多精彩
赞助商链接