Java、XML与数据库编程实践(三)
2008-01-05 20:10:34 来源:WEB开发网[系列文章:Java、XML与数据库编程实践(二)]
文件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
}
}
更多精彩
赞助商链接