为什么我批量建表报错?

viking168 2008-11-10
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class ads {
public static void main(String[] args){
Connection con = null;
Statement stmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","hr","123");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
for(int i=1;i<=31;i++){
String Index="";
if(i<10){
Index = "0"+(i+"");
}else{
Index = i+"";
}
String createTable = "create table OSS_DAY_"+Index+"_DETAIL(" +
"id INTEGER primary key," +
"loginName VARCHAR(20)," +
"loginIP VARCHAR(20)," +
"loginDate DATE," +
"logoutDate DATE," +
"labIP VARCHAR(20)," +
"timeDuration BIGINT)";
stmt = con.createStatement();
stmt.addBatch(createTable);
}
stmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

为什么我执行上面代码总是报错呢 ?请大家赐教!
FengShen_Xia 2008-11-11
把错误贴出来啊看看阿
brilliant2008 2008-12-11
int,integer,bigint不是字段的数据类型,他是plsql的变量的数据类型,虽然建表时不会报错,在其他的操作中会有问题的
honda418 2009-03-05
楼主多次一举。。。。

直接把建表脚本写到procedure里面,用个LOOP循环就搞定的。

另外,如果想找错误,把你的建表脚本换成insert语句试试,看能否成功,这样就可以找出问题了。。。。
Global site tag (gtag.js) - Google Analytics