分类:
2008-09-11 14:30:14
可能大家也都习惯了spring和hibernate对CLOB字段的处理,在spring中配置clob的oracle处理句柄,在hibernate中配置映射类型,然后就可以很轻松的以String 的形式处理大字段。
今天我做了个需求,需要以jdbc的方式从mysql导一些备份数据到oracle正式库,就查了一些资料,最后写了个例子: 1:首先:写个连接数据库的类,里面有返回mysq, oracle连接的方法
public Connection getConn(String flag){
Connection con=null;
try
{
if(flag.equals("1"))
{
Class.forName(“oracle.jdbc.driver.Driver”);
con = DriverManager.getConnection(“jdbc:oracle:thin:@IP:1521:数据库名字”,"name","password");
}
if(flag.equals("2"))
{
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/数据库名?user=用户名&password=密码&useUnicode=true&characterEncoding=GBK");
}
}
catch(Exception e)
{
e.printStackTrace();
}
return con;
}
public Connection getConn(String flag){
Connection con=null;
try
{
if(flag.equals("1"))
{
Class.forName(“oracle.jdbc.driver.Driver”);
con = DriverManager.getConnection(“jdbc:oracle:thin:@IP:1521:数据库名字”,"name","password");
}
if(flag.equals("2"))
{
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/数据库名?user=用户名&password=密码&useUnicode=true&characterEncoding=GBK");
}
}
catch(Exception e)
{
e.printStackTrace();
}
return con;
}
view plaincopy to clipboardprint?
public void setData() {conn = new Conn();
try {
String sqlfrom = "select p.id,p.content from table p order by p.id ";
String sqlinsert = "insert into table values(?,?)";
con = conn.getConn("2");
stmt = con.createStatement(); //从mysql取出大字段
rs = stmt.executeQuery(sqlfrom);
con = conn.getConn("1");
PreparedStatement pstmt = con.prepareStatement(sqlinsert); //向oracle中插入大字段
int i = 0;
while (rs.next()) {
[1]
【责编:landy】
--------------------next---------------------