爲什麼會發生這種情況,我該如何解決?java.sql.SQLException:在index :: 1處缺少IN或OUT參數。我該如何解決這個異常?
public void insertXML()
{
pars.getParsare();
Hashtable<Integer,ArrayList<Object>> has = pars.getHashTable();
ArrayList<String> query = new ArrayList<String>();
Enumeration en = has.elements();
while(en.hasMoreElements())
{
ArrayList<Object> aux = (ArrayList<Object>)en.nextElement();
String name = "";
Element e = (Element) aux.get(0);
name = e.getName();
System.out.println("NUMEEE " + e.getName());
ArrayList<String> col_name = getColName(name.toUpperCase());
ArrayList<String> col_type = getColType(name.toUpperCase());
String col_name_string = "";
String val = "?";
for(int i=0;i<col_name.size()-1;i++)
{
col_name_string = col_name_string + col_name.get(i).toLowerCase() + ", ";
val = val + ",?";
}
col_name_string = col_name_string + col_name.get(col_name.size()-1).toLowerCase();
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
System.out.println("INSERT INTO "+ name +"("+ col_name_string +") VALUES"
+ "("+ val +")");
String insertTableSQL = "INSERT INTO "+ name +"("+ col_name_string +") VALUES"
+ "("+ val +")";
for(int i=1;i<aux.size();i++)
{
dbConnection = bd.getConnection();
try {
preparedStatement = dbConnection.prepareStatement(insertTableSQL);
} catch (SQLException e3) {
e3.printStackTrace();
}
Attribute a = (Attribute)aux.get(i);
System.out.println(a.getValue());
if(col_type.get(i-1).equals("NUMBER"))
{
try {
System.out.println("intra in number: " + a.getDoubleValue());
preparedStatement.setDouble(i, a.getDoubleValue());
} catch (DataConversionException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
if(col_type.get(i-1).equals("VARCHAR2"))
{
System.out.println("intra in varchar " + a.getValue());
try {
preparedStatement.setString(i, a.getValue());
} catch (SQLException e1) {
e1.printStackTrace();
}
}
if(col_type.get(i-1).equals("DATE"))
{
System.out.println("intra in date: " + a.getValue());
String s = a.getValue();
String []s2 = new String[10];
s2 = s.split("-");
Time d = new Time(Integer.parseInt(s2[0]),Integer.parseInt(s2[1]),Integer.parseInt(s2[2]));
try {
preparedStatement.setTime(i, d);
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
try {
preparedStatement.executeUpdate();
System.out.println("MERGEEE");
} catch (SQLException e1) {
e1.printStackTrace();
}
System.out.println("Gata inserarea");
}
它提供了以下錯誤
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1821)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3579)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3665)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1352)
at BazaDeDateAcces.insertXML(BazaDeDateAcces.java:123)
at Main.main(Main.java:46)
你可以給你想要執行SQL查詢? –
我想從xml插入數據庫。 –
例如: –