我正在尝试创建一个表并在同一程序的同一个表上插入值。表已创建,插入查询未完成。无论我对插入字符串进行什么更改,我都会遇到相同的错误
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
Connection conn;
Statement smt;
ResultSet rs;
String ses_id=(String) session.getAttribute("mailid");
String add=request.getParameter("to_add");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","password");
smt=conn.createStatement();
System.out.println("connected");
try
{
rs=smt.executeQuery("create table "+add+"_inbox(sender_id varchar(20), subject varchar(20), message varchar(4000))");
System.out.println("created a table");
while(rs.next())
{
smt.executeUpdate("insert into "+add+"_inbox(sender_id,subject,message)"+" values('"+ses_id+"','"+request.getParameter("sub")+"','"+request.getParameter("msg")+"')");
System.out.println("done");
}
}
catch (SQLException e) {
System.out.println("exception");
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
} catch (ClassNotFoundException | SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally{}
}
我使用 eclipse 作为 servlet,使用 oracle10g 作为 db。 数据库已连接, 表已创建, 插入查询未完成。
最佳答案
您不会进入 while
循环,因为 rs
没有任何 rs.next
值。
您想在表中插入什么?我看到的是您想要插入一行,其参数来自 HttpSession 和 HttpServletRequest 。因此,请删除 while(rs.next)
循环。
关于java - ORA-01003 : no statement parsed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23866710/