Oracle JDBC connection issue - java

I'm trying to connect to Oracle dataBase in Java web project and this is the exception that I got :
java.sql.SQLException: Exception d'E/S: Got minus one from a read
call at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at
oracle.jdbc.driver.OracleConnection.(OracleConnection.java:404) at
oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314) at
java.sql.DriverManager.getConnection(Unknown Source) at
java.sql.DriverManager.getConnection(Unknown Source) at
mypack1.login.doPost(login.java:60) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 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:225)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.ow2.jonas.web.tomcat7.CheckOpenResourcesValve.invoke(CheckOpenResourcesValve.java:69)
at
org.ow2.jonas.web.tomcat7.tx.TransactionValve.invoke(TransactionValve.java:89)
at
org.ow2.jonas.web.tomcat7.ResetAuthenticationValve.invoke(ResetAuthenticationValve.java:95)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.ow2.jonas.web.tomcat7.versioning.VersioningValve.invoke(VersioningValve.java:105)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
and this's my connection code:
try {
Class.forName("oracle.jdbc.OracleDriver");
} catch (ClassNotFoundException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
out.println("<html><head><title>Hello World</title></head><body>");
out.println ("<h1>Where is your Oracle JDBC Driver?</h1>"+exceptionAsString+"</body></html>");
return;
}
out.println("<html><head><title>Hello World</title></head><body>");
out.println ("<h1>Oracle JDBC Driver Registered!</h1></body></html>");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:oracle:thin:#localhost:3010/apex/:XE","JEE","admin");
} catch (SQLException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
out.println("<html><head><title>Hello World</title></head><body>");
out.println ("<h1>Connection Failed! Check output console</h1>"+exceptionAsString+"</body></html>");
e.printStackTrace();
return;
}
if (connection != null) {
out.println("<html><head><title>Hello World</title></head><body>");
out.println ("<h1>You made it, take control your database now!</h1></body></html>");
} else {
out.println("<html><head><title>Hello World</title></head><body>");
out.println ("<h1>Failed to make connection!</h1></body></html>");
}

Related

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver [Eclipse, Tomcat] [duplicate]

This question already has answers here:
How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
(13 answers)
Closed 6 years ago.
I know that's an over-asked question, but still I can't get this thing right.
I'm running a web application on Eclipse who has to interact with a mysql database. It all runs on a tomcat 7.0.27 server on localhost.
As much as I try to add my my mysql-connector-java-5.1.21-bin.jar to java build path, i still get the same error. Apparently it doesn't matter if I put it as an external lib or inside my Webcontent/META-INF/lib folder. Also tried different version of the connector (18 and 25).
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ns.Data.getInfo(Data.java:36)
at org.apache.jsp.home_jsp._jspService(home_jsp.java:78)
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:472)
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:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
this is the class that calls the driver:
package ns;
import java.sql.*;
import java.util.*;
public class Data {
public Data() {
};
public int prova = 4;
{
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://" + "127.0.0.1" + "/" + "test" + "?" + "user=" + "matt" + "&password=" + "pass");
Statement cmd = con.createStatement();
// TODO QUERY
ResultSet rs = cmd.executeQuery("SELECT * FROM carshare.passaggi");
con.close(); }
catch (Exception e) { System.out.println("Errore con DB o Query errata");
e.printStackTrace(); }
}
public String[] getInfo(String table, String column) {
String[] values = new String[100];
int i = 0;
String temp;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://" + "127.0.0.1" + "/" + "test" + "?" + "user=" + "matt" + "&password=" + "pass");
Statement cmd = con.createStatement();
// QUERY DA ESEGUIRE
ResultSet rs = cmd.executeQuery("SELECT * FROM carshare."+ table);
/*
while (rs.next()==true) {
temp = rs.getString(column);
System.out.print(temp);
values[i] = temp;
i++;
}
*/
con.close(); }
catch (Exception e) { System.out.println("Errore con DB o Query errata");
e.printStackTrace(); }
return values;
}
}
I'll welcome any advice or suggestion and will require additional info if needed.
It should be in your Webcontent/WEB-INF/lib folder not Webcontent/META-INF/lib

MySQL server configuration issues

As my topic says, the max_allowed_packet variable is not working.
I have a project in eclipse which loads csv-files up and store them into a mysql database through a servlet. For files smaller than 1M it works fine.
But my file is 95Mb big, and i have increase the 'max_allow_packet' variable in the my.ini file in the section [mysqld] up to 500M.
But it doesen't work. Eclipse gives my the same error.
Please take a look at this two pictures:
ECLIPSE
my.ini
[mysqld]
....
Thanks for help
*****EDIT*****
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (190104490 > 26214400). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3540)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2417)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2081)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2066)
at upload.Upload.doPost(Upload.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
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:100)
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:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
And this is the main-code where the file is upload and then store in mysql:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
Part part = request.getPart("file");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = part.getInputStream();
CSV csv = new CSV();
String name = null;
String header = part.getHeader("content-disposition");
if(header.contains("filename"))
{
name = header.substring(header.lastIndexOf("=") + 1, header.length()).replace("\"", "");
}
int i = 0;
while((i = in.read()) != -1 )
{
baos.write(i);
}
csv.setCsvFile(baos.toByteArray());
csv.setName(name);
baos.flush();
try {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/loadcsvup","*****","*******");
PreparedStatement stmt = con.prepareStatement("INSERT INTO loadcsvup.csvfiles (csv_name,file) VALUES (?,?)");
stmt.setString(1, csv.getName());
stmt.setBytes(2, csv.getCsvFile());
stmt.executeUpdate();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
***** EDIT 2 *****
Ok, now i have set the varibale also in de [client] section of the my.ini file. Seems to be work.
But now i got this error code:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.Util.getInstance(Util.java:372)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2081)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2066)
at upload.Upload.doPost(Upload.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
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:100)
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:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I've set the varibable like this:
[mysqld]
innodb_file_per_table=1
innodb_buffer_pool_size=1GB
innodb_log_file_size=128M
innodb_log_buffer_size=8M
Check points
Have you restarted mysql service after changing my.ini?
Run query SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet' and see the value. It should be 500MB (Equal bytes)
If the above query does not return 500M, then try running SET GLOBAL max_allowed_packet = 500 * 1024 * 1024. Then repeat step 2.
If value is shown as 500 M repeat your file upload.
If still problem persists, then it could be like mysql is looking at different variable.

PrimeFaces pagination not working and throwing exception

Iam using primefaces 5.0.i used data table in primefaces and displayed data from datatabase.Pagination tab displays in vertical wise doesn't display in proper manner. when i used pagination in datatable iam getting following exception
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.invoice.customerlisting.getcustomerlist(customerlisting.java:22)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:476)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:867)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:579)
at javax.faces.component.UIData.getRowCount(UIData.java:356)
at org.primefaces.component.api.UIData.calculateFirst(UIData.java:157)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:176)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
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:100)
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:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:361)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
... 56 more
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.invoice.customerlisting.getcustomerlist(customerlisting.java:22)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:476)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:867)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:579)
at javax.faces.component.UIData.isRowAvailable(UIData.java:343)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:422)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:401)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:683)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:234)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:196)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
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:100)
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:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:361)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
... 59 more
Here is my jsf page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
>
<h:head></h:head>
<body>
<h:form>
<p:dataTable value="#{customerlisting.getcustomerlist()}" var="cml" style="width:25px;height:30px;" rows="3" paginatorPosition="bottom" paginator="true">
<p:column>
<f:facet name="header">
Customer Id
</f:facet>
<h:outputText value="#{cml.customerid}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">Customer Name</f:facet>
<h:outputText value="#{cml.customername}"></h:outputText>
</p:column>
<p:column><p:commandButton value="Edit"/></p:column>
<p:column><p:commandButton value="Delete"/></p:column>
</p:dataTable>
</h:form>
</body>
</html>
Here is my bean class
package com.invoice;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.SessionScoped;
public class customerlisting {
public List<customer> getcustomerlist()
{
List<customer> cs=new ArrayList<customer>();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE","invoice","google");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select customerid,customername from customer order by customerid asc");
while(rs.next())
{
customer cm=new customer();
cm.setCustomerid(rs.getInt(1));
cm.setCustomername(rs.getString(2));
cs.add(cm);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return cs;
}
}
My customer class is
package com.invoice;
public class customer {
int customerid;
String customername;
public String getCustomername() {
return customername;
}
public void setCustomername(String customername) {
this.customername = customername;
}
public int getCustomerid() {
return customerid;
}
public void setCustomerid(int customerid) {
this.customerid = customerid;
}
}
I'm totally stuck with this pagination in primefaces please could some one help me with good solution
You got a Problem with polluting your server and the database with db-connections. This leads to your error, the DB does not allow any further connections.
To avoid this you must close the connections and free the resources on your server, as well on the DB-server.
I will post a snippet with correct resource-handling. Doing this, I will also use correct Java Code Conventions, especially: Classnames should start with a uppercase letter.
Class.forName("oracle.jdbc.driver.OracleDriver");
List<Customer> cs = new ArrayList<Customer>();
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE", "invoice", "google");
stmt = con.createStatement();
rs = stmt.executeQuery("select customerid,customername from customer order by customerid asc");
while (rs.next()) {
Customer cm = new Customer();
cm.setCustomerid(rs.getInt(1));
cm.setCustomername(rs.getString(2));
cs.add(cm);
}
} catch (Exception e) {
LOG.error("Error connecting to DB: " + e.getMessage(), e);
} finally {
try {
// close resources
rs.close();
stmt.close();
con.close();
} catch (Exception e) {// ignore
} finally {
// setting everything to null (allows Objects to be GC'd)
rs = null;
stmt = null;
con = null;
}
}
return cs;
Bare in mind: gathering a connection to DB is expensive. Consider using ConnectionPooling (like c3p0). ConnectionPooling will open a set of connections to the db for you and reuse them.
Your error is here:
at com.invoice.customerlisting.getcustomerlist(customerlisting.java:22)
That is this line:
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE","invoice","google");
You have a problem here on connection and not in primefaces. Isn't trying to open many connections? Try to open the connection just one time in some other method, and on getcustomerlist just create the statement.
public class customerlisting {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE","invoice","google");
public List<customer> getcustomerlist()
{
List<customer> cs=new ArrayList<customer>();
try
{
Statement stmt=con.createStatement();

generating a JavaAbstractMethod exception

i've written this code for adding photos to database and i'm not much into web application
so please help me out
// obtains input stream of the upload file
inputStream = filePart.getInputStream();
}
Connection conn = null; // connection to the database
String message = null; // message will be sent back to client
try {
// connects to the database
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/opmdb", "root", "sourabh");
// constructs SQL statement
String sql = "INSERT INTO photos (userId, photo) values (?, ?)";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setString(1, userName);
statement.setBinaryStream(2, inputStream);
here it is telling the error i've also used setBlob but the error remains the same
Exceptions and stacktrace is
java.lang.AbstractMethodError:com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
at org.onlinepicturemanager.addphotoservlet.AddPhotoServlet.doPost(AddPhotoServlet.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
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:472)
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:947)
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:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
change your code statement.setBinaryStream(2, inputStream);
to
statement.setBinaryStream(2, inputStream,file.length);
'setBinaryStream' method need 3 parameteres,add your file length in this method

getting null pointer exception while instantiating ServiceClient

I have made a client where i am creating a new object of ServiceClient. My code is:
private ServiceClient getClient(String action, String eprType){
String webinfFolder = request.getSession().getServletContext().getRealPath("/WEB-INF");
try{
if(wsSecurityEnabled){
configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(webinfFolder, webinfFolder + "/conf/axis2.xml");
serviceClient = new ServiceClient(configContext, null);
}else{
serviceClient = new ServiceClient();//Here i am getting nullpointerexception
}
}catch(IOException ioe){
ioe.printStackTrace();
}
targetEPR = new EndpointReference(eprType);
serviceClient.setOptions(getOptions(action));
serviceClient.addHeader(getUserNameHeaderElement());
System.out.println("Client Created");
return serviceClient;
}
Since my wsSecurityEnabled is false it comes to this code serviceClient = new ServiceClient();
and here i am getting nullpointer exception as:
java.lang.NullPointerException
at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:162)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:144)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:251)
at cts.remon.cctv.client.Consumer.getClient(Consumer.java:573)
at cts.remon.cctv.client.Consumer.requestCloseSession(Consumer.java:147)
at cts.remon.cctv.client.Consumer.doPost(Consumer.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
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:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
How to solve this error? Thanks in advance

Categories

Resources