I query a database to obtain all values from it.The query sometimes executes perfectly but at other times the query fails like this:
select * from myTable where objtype='EQUI' and scnrtype='C'
java.sql.SQLException: Column 'dataType' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1162)
at com.mysql.jdbc.ResultSetImpl.getCharacterStream(ResultSetImpl.java:2056)
at com.hastha.marerp.googlemaps.DBUtils.getScreenFields(DBUtils.java:672)
at com.hastha.marerp.googlemaps.DBUtils.getScreenFieldsJSON(DBUtils.java:754)
at com.hastha.marerp.googlemaps.DynamicMenuItemBuilder.doGet(DynamicMenuItemBuilder.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEondpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
The column dataType has char(8) as it's data type.
I have tried both rs.getString() and rs.getCharecterStream() where rs is the ResultSet obtained from this query.I think this has no effect on the problem because the error occurs before this line is even reached.
This is a description of myTable
This is my code:
public ArrayList<ScenarioFieldInfo> getScreenFields(String objType, String scenarioType)
{
System.out.println("Input args objType: "+objType+" and scenarioType: "+scenarioType);
PreparedStatement pst = null;
ResultSet rs = null;
ArrayList<ScenarioFieldInfo> scenarioFieldList = new ArrayList<ScenarioFieldInfo>();
try {
String sql = "select * from myTable where objtype='"+objType+"' and scnrtype='"+scenarioType+"'";
System.out.println(sql);
pst = (PreparedStatement) conn.prepareStatement(sql.toString());
rs = pst.executeQuery();
while(rs.next()){
ScenarioFieldInfo fieldInfo = new ScenarioFieldInfo();
fieldInfo.fieldName = rs.getString("fieldName");
fieldInfo.fieldLabel = rs.getString("FieldLabel");
//fieldInfo.sapType=rs.getString("dataType");
BufferedReader reader=new BufferedReader(rs.getCharacterStream("dataType"));
try {
String sapType=reader.readLine();
fieldInfo.sapType=sapType;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fieldInfo.parameter=rs.getString("PARAMETER");
scenarioFieldList.add(fieldInfo);
}
System.out.println("There are "+scenarioFieldList.size()+" screen fields");
} catch (SQLException e) {
e.printStackTrace();
}
finally
{
close(rs);
close(pst);
}
return scenarioFieldList;
}
I found that the code was crashing because I had getCharecterStream instead of getString which was causing an error in my case.Modiying the code to:
rs.getString("dataType");
fixed the issue
Related
I got Null pointer exception
"java.lang.NullPointerException"
refer below code for reference
Everything should be fine but not able to update data to the database(mySql)
<% try{
//reading request parameters
String projectName=request.getParameter("projectName").trim();
String status=request.getParameter("status").trim();
//String user = session.getAttribute("user").toString();
Connection connection = DAO.getConnection();
PreparedStatement pstmt = connection.prepareStatement("update project set status=? where projectName=?");
pstmt.setString(1,status);
pstmt.executeUpdate();
out.println("<h2 style='color:green'>Project Status has been updated</h2>");
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("<h2 style='color:red'>Please login to update your Status</h2>");
}
%>
Not able to update because of exception
refer below
Please anyone suggest me how to solve this exception...
java.lang.NullPointerException at org.apache.jsp.MyWorkPanelAction_jsp._jspService(MyWorkPanelAction_jsp.java:93)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
You missed the projectName...Try the code below
try{
//reading request parameters
String projectName=request.getParameter("projectName").trim();
String status=request.getParameter("status").trim();
//String user = session.getAttribute("user").toString();
Connection connection = DAO.getConnection();
PreparedStatement pstmt = connection.prepareStatement("update project set status=? where projectName=?");
pstmt.setString(1,status);
pstmt.setString(2,projectName); //Try this
pstmt.executeUpdate();
out.println("<h2 style='color:green'>Project Status has been updated</h2>");
}
catch(Exception ex)
{
ex.printStackTrace();
out.println("<h2 style='color:red'>Please login to update your Status</h2>");
}
I am trying to add some bunch of records in MySQL database usign jdbc in java. This program works absolutely fine for 100 records. But after 100 records i get following error.
Exception occured while obtaining
connectionjava.sql.SQLNonTransientConnectionException: Could not create connection to database server.
java.lang.NullPointerException
at com.rest.EmployeeRest.insertDesigMySQLData(EmployeeRest.java:446)
at com.rest.EmployeeRest.syncDesignation(EmployeeRest.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
After google about this error, someone tell to use telnet command on localhost 3306(MySQL port). and it gives me "Too many connections" error.
Can anyone help me to solve this issue.
API code to get Data and add to MySQL:
ArrayList<Employee> arrDesig = getAllDesig();
setTotRecords(arrDesig.size());
System.out.println("Oracle TotRecords = "+getTotRecords());
if(arrDesig.size() > 0){
for(int iCnt=0; iCnt<arrDesig.size(); iCnt++){
if(insertDesigMySQLData(arrDesig.get(iCnt)) == 1){
mysqlDat++;
}
System.out.println("MySQL inserted data = "+mysqlDat);
}
if(getTotRecords() == mysqlDat){
retval = 1;
}else{
retval = 0;
}
}else{
retval = 0;
}
MySQL code to add:
int retval = 0;
OracleDataSource objMySQLDataSource = new OracleDataSource("mysql");
try{
Connection connection = objMySQLDataSource.getDbConnection();
CallableStatement pstmt=connection.prepareCall("{call addDesig(?,?,?)}");
pstmt.setString(1,objEmployee.getDesig_id());
System.out.println("getDesig_id() = "+objEmployee.getDesig_id());
pstmt.setString(2,objEmployee.getDesig_nm());
System.out.println("getDesig_nm() = "+objEmployee.getDesig_nm());
pstmt.registerOutParameter(3, Types.NUMERIC);
pstmt.executeUpdate();
retval = pstmt.getInt(3);
pstmt.close();
}catch (Exception e) {
retval = 0;
e.printStackTrace();
}finally{
objMySQLDataSource.connectionClose();
}
return retval;
Oracle Connection
OracleDataSource(){
setUrl("jdbc:oracle:thin:#dburl");
setDriver("oracle.jdbc.OracleDriver");
setUserName("admin");
setPassword("**********");
}
MySQL Connection
OracleDataSource(String mysql){
setUrl("jdbc:mysql://localhost:3306/academicdb?verifyServerCertificate=false&useSSL=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
setDriver("com.mysql.cj.jdbc.Driver");//com.mysql.jdbc.Driver
setUserName("root");
setPassword("");
}
public Connection getDbConnection() {
Connection con = null;
try{
Class.forName(getDriver());
con = DriverManager.getConnection(getUrl(), getUserName(), getPassword());
} catch (Exception se) {
System.out.println("Exception occured while obtaining connection" + se.toString());
}
return con;
}
I don't understand why I am getting this error.. In my web application I have used many methods where I execute insert, select, update etc where all of them works correctly without errors... Now I want to implement a delete action. So, I have:
public void deleteBox(Label label)
throws SQLException, ClassNotFoundException {
System.out.println("Deleting box from BOXES");
sq = "DELETE FROM BOXES WHERE product=? AND version=? AND productionD=? AND AA=?";
try {
Class.forName(typeDB);
c = DriverManager.getConnection(path);
PreparedStatement stm = c.prepareStatement(sq);
stm.setString(1, label.getProduct());
stm.setString(2, label.getVersion());
stm.setString(3, label.getDateProduction());
stm.setString(4, label.getPacketNumber());
stm.executeUpdate();
} catch (SQLException e) {
System.out.println("hereeee error: " + e.getMessage());
e.printStackTrace();
} finally {
if (stm != null)
stm.close(); //<---
if (c != null)
c.close();
}
}
where path and typeDB are defined as:
private final String path = "jdbc:sqlite:C:\\DB_LABELS\\labels.sqlite";
private final String typeDB= "org.sqlite.JDBC";
and in the start of the class:
private Connection c = null;
PreparedStatement stm = null;
This method is called from the servlet here:
try{
Label box = (Label) session.getAttribute("boxFound");
action.deleteBox(box); //here I call the method
//some other stuff here..
action.addTransaction(box, "extract", timeStamp1, user.getId());
old = action.searchQuantityOfPackage(box);
}catch(SQLException | ClassNotFoundException e){
System.err.println("Exception at extract. More: " + e);
}
When it is executed I get an error:
Deleting box from BOXES
Exception at extract. More: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
and all the other commands aren't executed inside the try. I don't understand why is this happening. As I said in the begging I use the same setting for other sql actions so both path and typeDB must be defined correctly. If I delete action.deleteBox(box); no error is happening, so sth is happening in this method...
ALSO
I forgot to mention that the delete of the row in the table BOXES is happening despite the error!
I add also the ful stack trace
Exception at extract. More: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
at org.sqlite.core.DB.newSQLException(DB.java:890)
at org.sqlite.core.CoreStatement.internalClose(CoreStatement.java:109)
at org.sqlite.jdbc3.JDBC3Statement.close(JDBC3Statement.java:35)
at gr.products.labelInventory.ActionsDB.deleteBox(ActionsDB.java:557)
at gr.products.labelInventory.Inventory.processRequest(Inventory.java:285)
at gr.products.labelInventory.Inventory.doGet(Inventory.java:652)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gr.products.labelInventory.LogFilter.doFilter(LogFilter.java:22)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:724)
this line at gr.products.labelInventory.ActionsDB.deleteBox(ActionsDB.java:557) points to the <-- i put in the code.
I am creating a webapp in which a user can set alert for certains network documents. this date is stored in a mysql DB along with a bunch of other data which is encrypted on insert using AES_ENCRYPT.
the prcedure for insert looks like this:
CREATE DEFINER=`service01`#`%` PROCEDURE `insert_secure_alert`(
IN master_secret VARCHAR(100),
IN path VARCHAR(300),
IN creation DATE,
IN expiration DATE,
IN alert_name VARCHAR(300),
IN alert_comment VARCHAR(300)
)
BEGIN
INSERT INTO `fujitsu_consensus_core`.`alert`
(`id`,
`path`,
`creation`,
`expiration`,
`name`,
`comment`)
VALUES
(0,
AES_ENCRYPT(path, master_secret),
AES_ENCRYPT(creation, master_secret),
AES_ENCRYPT(expiration, master_secret),
AES_ENCRYPT(alert_name, master_secret),
AES_ENCRYPT(alert_comment, master_secret));
END
This is al working just fine, I am however facing some issues when retrieving this data using a stored procedure. the class responsible for this retrieval looks like this:
package com.fujitsu.database;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import com.fujitsu.consensus.helper.StreamToJson;
public class RetrieveSecureAlert extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = -6379032803226212817L;
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException{
try {
JSONObject obj = StreamToJson.convertStreamToJson(req.getInputStream());
String path = (String) obj.get("path");
CallableStatement cs = AccessObject.getConnectionObject().prepareCall("{CALL `fujitsu_consensus_core`.`retrieve_secure_alert`(?,?}");
cs.setString(1, path);
cs.setString(2, "FUJITSU");
cs.execute();
ResultSet result = cs.getResultSet();
System.out.println("RESULT!");
while(result.next()){
System.out.println(result.getString("id"));
System.out.println(result.getString("decryptd_path"));
System.out.println(result.getString("decrypted_creation"));
System.out.println(result.getString("decrypted_expiration"));
System.out.println(result.getString("decrypted_name"));
System.out.println(result.getString("decrypted_comment"));
}
} catch (ParseException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The corresponding mysql stores procdure looks like this:
CREATE DEFINER=`service01`#`%` PROCEDURE `retrieve_secure_alert`(IN path_key VARCHAR(300), IN master_secret VARCHAR(100))
BEGIN
DECLARE v_encrypted_path VARBINARY(300);
DECLARE v_encrypted_creation VARBINARY;
DECLARE v_encrypted_expiration VARBINARY;
DECLARE v_encrypted_name VARBINARY(300);
DECLARE v_encrypted_comment VARBINARY(300);
SELECT path INTO v_encrypted_path FROM fujitsu_consensus_core WHERE path = AES_ENCRYPT(path_key, master_secret);
SELECT creation INTO v_encrypted_creation FROM fujitsu_consensus_core WHERE path = AES_ENCRYPT(path_key, master_secret);
SELECT expiration INTO v_encrypted_expiration FROM fujitsu_consensus_core WHERE path = AES_ENCRYPT(path_key, master_secret);
SELECT `name` INTO v_encrypted_name FROM fujitsu_consensus_core WHERE path = path = AES_ENCRYPT(path_key, master_secret);
SELECT `comment` INTO v_encrypted_comment FROM fujitsu_consensus_core WHERE path = AES_ENCRYPT(path_key, master_secret);
SELECT id,
AES_DECRYPT(v_encrypted_path, master_secret) AS decryptd_path,
AES_DECRYPT(v_encrypted_creation, master_secret) AS decrypted_creation,
AES_DECRYPT(v_encrypted_expiration, master_secret) AS decrypted_expiration,
AES_DECRYPT(v_encrypted_name, master_secret) AS decrypted_name,
AES_DECRYPT(v_encrypted_comment, master_secret) AS decrypted_comment
FROM fujitsu_consensus_core.alert
WHERE path = AES_ENCRYPT(path_key, master_secret);
END
The stack trace:
java.sql.SQLException: Unable to retrieve metadata for procedure.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.CallableStatement.extractProcedureName(CallableStatement.java:659)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:498)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:403)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4161)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4235)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4209)
at com.fujitsu.database.RetrieveSecureAlert.doPost(RetrieveSecureAlert.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
So the big question is, how do I retrieve records from a stored procedure in mysql using the java.sql.callablestatement which decrypts my records?
I found the error however, the sql string in the callablestatement can not contain ` but should contain '
I'm Developing a Web Application using JSF & PrimeFaces. I have two classes Inputs & DBConn. And i'm executing a SQL command like this
SQL="SELECT COUNT(*) FROM TXN_HEADER WHERE REQUEST_DATE='01-AUG-2014'"
And then in the DBConn class i call the next() method on the ResultSet object inside a while loop condition to print the result.
This works fine and gives me an output.
But when i try to call that ResultSet object to get an output using the same scenario above (using that while loop inside the Inputs class) it gives me the following exception.
java.sql.SQLException: Result set after last row
at oracle.jdbc.driver.GeneratedScrollableResultSet.getString(GeneratedScrollableResultSet.java:879)
at Inputs.commandButton(Inputs.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:245)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:277)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Then i assumed that after the first use of the next() method the cursor is still in the end though i used the next() method again in that Inputs class.
So i tried using the .beforeFirst() method before going to the 2nd while loop to reset the cursor back to the top. But it gave me the same error again.
Then i tried commenting the 1st while loop i access in the DBConn class so the cursor is at the top for sure. But then it gives me the following error.
java.sql.SQLException: ResultSet.next was not called
at oracle.jdbc.driver.GeneratedScrollableResultSet.getString(GeneratedScrollableResultSet.java:874)
at Inputs.commandButton(Inputs.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:245)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:277)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
How do i resolve this? This is my first time developing a Database Application.
And sorry about these bunch of sys.prints, I used them for debugging.
These are the two classes related to this case:
Inputs Class
import java.sql.SQLException;
import javax.annotation.ManagedBean;
#ManagedBean
public class Inputs {
private String date;
private String showRes;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getShowRes() {
return showRes;
}
public void setShowRes(String showRes) {
this.showRes=showRes;
}
public void commandButton(){
DBConn nCon=new DBConn();
Calculations nCalc=new Calculations();
nCalc.setPieChartSQL(getDate());
nCon.setSQL(nCalc.getPieChartSQL());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
try {
System.out.println(nCon.getResultSet().getString(1));
//nCon.getResultSet().beforeFirst();
while(nCon.getResultSet().next()){
System.out.println("++++++++++++");
System.out.println(nCon.getResultSet().getString(1));
System.out.println("++++++++++++");
setShowRes(nCon.getResultSet().getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("777777777777777777777");
}
}
DBConn Class
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.pool.OracleDataSource;
public class DBConn {
private String sql;
private ResultSet rs;
public ResultSet getResultSet(){
try {
OracleDataSource dataSource=new OracleDataSource();
dataSource.setURL("jdbc:oracle:thin:#172.16.20.45:1521:ABS");
dataSource.setUser("<user>");
dataSource.setPassword("<pass>");
OracleConnection con = (OracleConnection)dataSource.getConnection();
con.setAutoCommit(false);
Statement stmnt = con.createStatement();
rs = stmnt.executeQuery(sql);
System.out.println("-----------");
System.out.println(rs);
System.out.println("-----------");
System.out.println(rs);
System.out.println("-----------");
while(rs.next()){
System.out.println("*************");
System.out.println(rs.getString(1));
System.out.println("*************");
}
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void setSQL(String sql) {
this.sql=sql;
}
}
I think the problem is in the way you get the resultset. Each time you call nCon.getResultSet() it returns a new resultset. That means you call next method of one resultset object and calls getString(1) in another. Here is my solution.
public void commandButton(){
DBConn nCon=new DBConn();
Calculations nCalc=new Calculations();
nCalc.setPieChartSQL(getDate());
nCon.setSQL(nCalc.getPieChartSQL());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
try {
ResultSet rst=nCon.getResultSet();
rst.beforeFirst();
while(rst.next()){
System.out.println("++++++++++++");
String str=rst.getString(1);
System.out.println("++++++++++++");
setShowRes(str);
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("777777777777777777777");
}
Your getResultMethod() is putting cursor at the end of the ResultSet. And this Exception occurs because you are not calling next() and trying to access the ResultSet in your below method
public void commandButton(){
DBConn nCon=new DBConn();
Calculations nCalc=new Calculations();
nCalc.setPieChartSQL(getDate());
nCon.setSQL(nCalc.getPieChartSQL());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
try {
System.out.println(nCon.getResultSet().getString(1)); //here rs.next() should be called first
//nCon.getResultSet().beforeFirst();
while(nCon.getResultSet().next()){
System.out.println("++++++++++++");
System.out.println(nCon.getResultSet().getString(1));
System.out.println("++++++++++++");
setShowRes(nCon.getResultSet().getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("777777777777777777777");
}
Solution
try{
while(rs.next()){
System.out.println(nCon.getResultSet().getString(1));
}
......
}