【发布时间】:2014-08-30 02:44:59
【问题描述】:
我有一个如下所示的 java 类:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package oracletree1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author oracle
*/
public class TREEUPDATER {
int Levels;
int NodeId;
int ParentId;
String FatherID;
int ChildBed_new;
int ChildBes_new;
int ChildMande_new;
int ChildBed_old;
int ChildBes_old;
int ChildMande_old;
int ParentBed;
int ParentBes;
int ParentMande;
String Script;
String ValueState;
String TreeState;
public TREEUPDATER() throws SQLException {
}
public void updating(int levels, int NodeIds, int childBed_old, int childBes_old, int childMande_old) throws SQLException {
this.ChildBed_old = childBed_old;
this.ChildBes_old = childBes_old;
this.ChildMande_old = childMande_old;
this.Levels = levels;
this.NodeId = NodeIds;
String[] array;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
return;
}
System.out.println("Oracle JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.1.12:1521:orcl", "tree1",
"oracle");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
return;
}
if (connection != null) {
Statement stmt = connection.createStatement();
Statement stmt2 = connection.createStatement();
// stmt.executeUpdate("insert into test.java_test(id) values (21)");
ResultSet rs = stmt.executeQuery("SELECT * from value" + "where nodeid = " + NodeId);
ResultSet rs2 = stmt.executeQuery("select * from tree where id = " + NodeId);
while (rs.next()) {
this.FatherID = rs2.getNString("FatherID");
this.ChildBed_new = rs2.getInt("bed");
this.ChildBes_new = rs2.getInt("bes");
this.ChildMande_new = rs2.getInt("mande");
array = new String[100000];
array = FatherID.split("_");
for (int i = 0; i < array.length; i++) {
ResultSet rs3 = stmt2.executeQuery("SELECT * from tree" + "where id = " + array[i]);
this.ParentId = rs3.getInt("id");
this.ParentBed = rs3.getInt("bed");
this.ParentBes = rs3.getInt("bes");
this.ParentMande = rs3.getInt("mande");
connection.setAutoCommit(false);
ParentBed = ChildBed_new - ChildBed_old;
ParentBes = ChildBes_new - ChildBes_old;
this.TreeState = rs2.getNString("state");
if (TreeState.equalsIgnoreCase("BED")) {
this.ParentMande = ParentBed - ParentBes;
} else {
this.ParentMande = ParentBes - ParentBed;
}
this.Script = ("update value set bed = bed + " + ParentBed + " and bes = bes + " + ParentBes + "and mande = mande + " + ParentMande
+ "where id = " + ParentId);
stmt2.executeUpdate("" + Script);
}
}
}
}
}
我有一个主类,如下所示:
/* * 要更改此许可标头,请在项目属性中选择许可标头。 * 要更改此模板文件,请选择工具 |模板 * 并在编辑器中打开模板。 */
包 oracletree1;
导入 java.sql.SQLException;
/**
*
* @author oracle
*/
public class OracleTree1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
// TODO code application logic here
TREEUPDATER t = new TREEUPDATER();
}
}
我已将这些类加载到 oracle 数据库 11gr2 中,并且我想使用触发器来运行 updates() 方法。所以我正在创建一个这样的程序:
CREATE OR REPLACE PROCEDURE PROCEDURE4
(
LEVELS IN NUMBER
, NODEID IN NUMBER
, CHILDBED_OLD IN NUMBER
, CHILDBES_OLD IN NUMBER
, CHILDMANDE_OLD IN NUMBER
) AS
LANGUAGE java name 'TREEUPDATER.updating(1,2,3,4,5)';
但是当我想编译和运行这个程序时,我有这个错误:
Error: PL/SQL: Compilation unit analysis terminated
Error(9,16): PLS-00311: the declaration of "TREEUPDATER.updating(1,2,3,4,5)" is incomplete or malformed
任何人都可以解决这个问题吗? 谢谢
【问题讨论】:
-
你最好提高你的英语。你的问题很混乱。
-
您的代码非常适合 SQL 注入。
-
这是测试代码,不用担心sql注入
标签: java stored-procedures oracle11g