[英]store arraylist in oracle database
this is my code for storing arraylist in database but i am facing some problem that is only the first element of arraylist is stored in database. 这是我在数据库中存储arraylist的代码,但是我遇到了一些问题,只有arraylist的第一个元素存储在数据库中。 pls help 请帮助
int invoice_no,bookno;
static ArrayList<Integer> reference=new ArrayList<>();
static ArrayList<Integer> quantity2 = new ArrayList<>();
public void abc1()
{
try
{
System.out.println("hello");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","anchit");
Statement statement=connection.createStatement();
ResultSet r1=statement.executeQuery("select max(invoice_no) from invoice_detail");
int a=1;
while(r1.next())
{
a=r1.getInt(1);
System.out.println(r1.getInt(1));
}
System.out.println("a="+a);
invoice_no=a+1;
if(invoice_no%50==0)
bookno=(invoice_no/50);
else
bookno=(invoice_no/50)+1;
System.out.println(invoice_no+","+bookno);
System.out.println(reference);
for(int i=0;i<reference.size();i++)
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection1=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","anc123hit");
Statement statement1=connection1.createStatement();
//int b=
System.out.println(reference.get(i));
//int c=quantity2.get(i);
ResultSet r=statement1.executeQuery("insert into invoice_detail values("+invoice_no+","+bookno+","
+reference.get(i)+","+quantity2.get(i)+", to_char(sysdate,'dd-mon-yy'),'anchit','abcd')");
r.next();
connection1.close();
}
connection.close();
}
catch(Exception e)
{}
}
this is my code for storing arraylist in database but i facing some problem only the first element of arraylist is stored in database. 这是我在数据库中存储arraylist的代码,但是我遇到一些问题,只有arraylist的第一个元素存储在数据库中。 pls help 请帮助
This behavior comes when you try to use .executeQuery()
on DML ( insert
, update
, delete
) operation, you should use .executeUpdate()
instead. 这种行为来当您尝试使用.executeQuery()
在DML( insert
, update
, delete
)操作,你应该使用.executeUpdate()
来代替。
Statement statement1=connection1.createStatement();
//int b=
System.out.println(reference.get(i));
//int c=quantity2.get(i);
//ResultSet r=;
statement1.executeUpdate("insert into invoice_detail values("+invoice_no+","+bookno+","
+reference.get(i)+","+quantity2.get(i)+", to_char(sysdate,'dd-mon-yy'),'anchit','abcd')");
//r.next();
Usually compiler thrown error that your query doesn't return ResultSet when you use .executeQuery on DML 通常,在DML上使用.executeQuery时,编译器会抛出错误,即查询不返回ResultSet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.