您好我正在使用JSF 2.2和Oracle XE编写库管理系统。我有书籍和作者表。在JSF中,我有书籍和authos页面。在Books页面中,用户可以输入书籍和书籍的编辑名称,并将其写入数据库中的Editor属性。我想编写一个Oracle函数,它接受编辑的名称并将其插入到Author表中。在Author表中有Name和Surname属性。因此,函数应该从编辑器中取出一行,将其分隔为Name和Surname,并将它们插入到Author表中。为此我编码下面的代码。我采取并分离了编辑姓名和姓氏。并将它们传递给String数组。问题是Oracle功能。我不知道怎么写。如果此作者已在此表中,我们将如何控制Author表。当然我不想在桌子上添加同样的人。我为此寻找互联网但没有任何东西。如果这个问题很容易,我很抱歉。请帮我。我会为此付出代价。感谢。
public void AuthorNames() throws SQLException{
String authorNames = "";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","Alparslan-PC","123456");
ps = con.prepareStatement("SELECT DISTINCT EDITOR FROM BOOK");
ResultSet rs = ps.executeQuery();
for(int count = 0; rs.next(); count++){
authorNames += " " + rs.getString("EDITOR");
}
for(int count = 0; count<authorNames.length(); count += 2){
NameSurname = authorNames.split(" ");
}
sqlFunction(NameSurname);
} catch (ClassNotFoundException ex) {
Logger.getLogger(BorrowerBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void sqlFunction(String[] NameSurname) throws SQLException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","Alparslan-PC","123456");
for(int count = 0; count < NameSurname.length; count++){
ps = con.prepareStatement("CREATE [OR REPLACE] FUNCTION author_names( " + NameSurname[count] + " , "
+ NameSurname[count+1] + " RETURN 0 ");
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(BorrowerBean.class.getName()).log(Level.SEVERE, null, ex);
}
}