Ich habe keine Ahnung wieso dieser *** Fehler auftritt.
Habe überall System.outs eingefügt um zu sehen wieso passiert. Wieso weiss ich nicht, aber wo. Es passiert genau hier:
Danach ist das resset vom qryFields weg. Das insert Query ist garantiert fehlerfrei, es meldet keinen und macht den Eintrag.
Ich kriege immer die Meldung:
Bisschen Code:
Query.java
insertForm.jsp:
Habe überall System.outs eingefügt um zu sehen wieso passiert. Wieso weiss ich nicht, aber wo. Es passiert genau hier:
Code:
Query qryInsert = new Query(oc, "Select * from gds.state");
Ich kriege immer die Meldung:
SELECT * FROM GDS.STATE
ResSet4
INSERT INTO GDS.STATE (STATE_ID_S, COUNTRY_ID_S, SEARCH_AS_S, STATE_S) values ('qwer', 'qwer', 'qwer', 'qer')
13.10.2005 08:57:39 org.apache.catalina.core.StandardWrapperValve invoke
SCHWERWIEGEND: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at oracle.jdbc.driver.OracleResultSetMetaData.<init>(OracleResultSetMetaData.java:89)
at oracle.jdbc.driver.ScrollableResultSet.getMetaData(ScrollableResultSet.java:1776)
at org.apache.jsp.insertForm_jsp._jspService(org.apache.jsp.insertForm_jsp:157)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Bisschen Code:
Query.java
Code:
public class Query
{
public ResultSet resSet;
private boolean error = false;
private String strE = "";
private int intE;
public Query(OraConnection oc, String query)
{
try
{
resSet = oc.stmt.executeQuery(query);
}
catch(SQLException e)
{
error = true;
strE = e.toString();
intE = e.getErrorCode();
return;
}
}
public boolean isError()
{
return error;
}
public String getError()
{
return strE;
}
public int getErrorNr()
{
return intE;
}
}
insertForm.jsp:
Code:
<%
//// Form viewing ////
//Getting parameters
String strTable = request.getParameter("table");
String strSubmit = request.getParameter("hSubmit");
//Getting connection and execute query
OraConnection oc = new OraConnection(application.getInitParameter("jdbcUrl"));
Query qryField = new Query(oc, "SELECT * FROM " + strTable);
System.out.println("SELECT * FROM " + strTable);
qryField.resSet.next();
//Creating vars for later use
int iColumnCount = qryField.resSet.getMetaData().getColumnCount();
System.out.println("ResSet" + qryField.resSet.getMetaData().getColumnCount());
//// Insert procedure ////
if(strSubmit != null)
{
//Vars
StringBuilder sbSql = new StringBuilder();
Vector vecFields = new Vector();
String strField = null;
String strError = "<font color='green'>Record successfully inserted</font>";
//Get all fields
Enumeration enuFields = request.getParameterNames();
//Go through all elements and build sql statement
sbSql.append("INSERT INTO " + strTable + " (");
//Add all fields
while(enuFields.hasMoreElements())
{
strField = enuFields.nextElement().toString();
if(!strField.equals("table") &&
!strField.equals("hSubmit"))
{
sbSql.append(strField + ", ");
vecFields.addElement(strField);
}
}
//Cut last two characters and add next sql part
sbSql.delete(sbSql.length()-2, sbSql.length());
sbSql.append(") values (");
for(int i = 0; i < vecFields.size(); i++)
{
sbSql.append("'" + request.getParameter(vecFields.get(i).toString()) + "', ");
}
//Cut last 2 characters and finish sql statement
sbSql.delete(sbSql.length()-2, sbSql.length());
sbSql.append(")");
//Execute query
System.out.println(sbSql.toString());
Query qryInsert = new Query(oc, sbSql.toString());
//Check for errors
if(qryInsert.isError())
{
strError = "<font color='red'>" + qryInsert.getErrorNr() + "</font>";
System.out.println("error");
}
}
%>