create_PaperBean.java
package Beans;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class create_paperBean extends org.apache.struts.action.ActionForm {
private String table_name;
public String getTable_name() {
return table_name;
}
public void setTable_name(String table_name) {
this.table_name = table_name;
}
public String createDB(){
String str = "creation_failed";
try{
Statement st = DBConnection.DBConnection.DBConnect();
int insert = st.executeUpdate("CREATE TABLE "+table_name+"(ques_no int(11) NOT NULL PRIMARy KEY,"
+ "ques_name varchar(45),ans1 varchar(45),ans2 varchar(45),ans3 varchar(45),"
+ "ans4 varchar(45),correct_ans varchar(45))");
System.out.println(insert);
if(insert > 0)
str = "created";
} catch (SQLException ex) {
Logger.getLogger(create_paperBean.class.getName()).log(Level.SEVERE, null, ex);
}
return str;
}
}
我正在使用 struts,当执行这个 bean 时,会在数据库中创建一个表,但 insert 的值仍然为零!因此,我无法进入正确的页面以进一步运行 Web 应用程序。我究竟做错了什么?