Hibernate exception occured after running few min in server org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326) at FetchCoeff.testing(FetchCoeff.java:37) at UDPServer.main(UDPServer.java:70) Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database! at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417) ... 6 more Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319) at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) ... 9 more Exception in thread "main" java.lang.NullPointerException at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1009) at java.lang.Float.parseFloat(Float.java:439) at ConvertReadings.Convertd(ConvertReadings.java:39) at UDPServer.main(UDPServer.java:73)
xml file <hibernate-configuration> <session-factory> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="connection.url"> jdbc:mysql://localhost:3306/praxeye1 </property> <property name="connection.username"> enviromote </property> <property name="connection.password"> enviromote123 </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="c3p0.validate"> true </property> <property name="current_session_context_class"> thread </property> <property name="hibernate.cache.provider_class"> org.hibernate.cache.NoCacheProvider </property> <property name="c3p0.min_size"> 5 </property> <property name="c3p0.max_size"> 100 </property> <property name="c3p0.timeout"> 0 </property> <property name="c3p0.max_statements"> 0 </property> <property name="c3p0.idle_test_period"> 3000 </property> <property name="c3p0.acquire_increment"> 3 </property> <property name="hibernate.connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider </property> <property name="show_sql">false</property> <mapping resource="SensorReadings.hbm.xml"/> </session-factory> </hibernate-configuration>
hibernate code public class FetchCoeff { public String[] testing(String x, String y) { Session session= null ; Transaction tx= null; String c[] = new String[30]; System.out.println("entering main"); Configuration cfg= new Configuration(); cfg.configure("Hibernate.cfg.xml"); System.out.println("configuration is done"); session = cfg.buildSessionFactory().openSession(); System.out.println("connection got"); try{ tx = session.beginTransaction(); String q= "SELECT d.c1, d.c0, d.DevID, d.SensorType FROM SensorReadings d WHERE d.DevID= :DevID AND d.SensorType= :SensorType"; Query query = session.createQuery(q); query.setParameter("DevID",x); query.setParameter("SensorType", y); System.out.println("query executed"); for(Iterator it=query.iterate();it.hasNext();){ Object[] ob = (Object[]) it.next(); System.out.println("Coefficent 1 is :" + ob[0]); System.out.println("Coefficent 0 is :" + ob[1]); System.out.println("Device ID is : " + ob[2]); System.out.println("Sensor type is : " + ob[3]); c[1]= (String)ob[0]; c[0]= (String)ob[1]; tx.commit(); session.close(); } }catch(HibernateException e){ System.out.println("Hibernate exception occured"); e.printStackTrace(); }catch(Exception d){ System.out.println("exception occured"); d.printStackTrace(); } finally { //session.close(); } return c; } }
converting part
public class ConvertReadings { public String Convertd(String a, String b, String c1, String c0 ) throws Exception { Converter con= new Converter(); int x; double i = Float.parseFloat(a); if (b.equalsIgnoreCase("HUM")) { double c=Float.parseFloat(c1); double d=Float.parseFloat(c0); x=con.convert(c, d, i); return String.valueOf(x); } else if (b.equalsIgnoreCase("CO")) { double c=Float.parseFloat(c1);; double d=Float.parseFloat(c0); x=con.convert(c, d, i); return String.valueOf(x); }
public class Converter { public int convert(double c, double d, double i){ int x; i = (c * i) + d; x = (int) (Math.ceil(i)); return x; }
}
final running code DatagramSocket serverSocket = new DatagramSocket(20001); byte[] receiveData = new byte[1024]; while (true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); System.out.println(sentence); try { InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); System.out.println("The Client IP Address and Port Number is" + IPAddress + port);// displaying the above 2 line o/p
String s[] = sentence.split(","); Calendar currentDate = Calendar.getInstance(); // NEW
SimpleDateFormat sdfDestination = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); // NEW // parse the date into another format
String strDate = sdfDestination.format(currentDate.getTime()); // NEW s[2] = strDate; // NEW
if (s[0].equalsIgnoreCase(pwd)) { s[0] = "password secret"; System.out.println(s.length); j = 4; while (j != s.length) { a = sm.sensorMap(s[j]); System.out.println(a); String ab[] = a.split(","); b = ab[0]; c = ab[1]; String coeff[] =fc.testing(s[1], b);// here i am getting problem String conv = cr.Convertd(s[j + 1], b, coeff[1], coeff[0]); // even here i am getting exception
String sql = "INSERT INTO readings_db (DevID,Date,Time,SensorPNo,SensorType,Reading,ConvertedReading) values('" + s[1] + "','" + s[2] + "','" + s[3] + "','" + c + "','" + b + "','" + s[j + 1] + "','" + conv + "')";
storageHandler.store(sql); //Gives the sql to persist to the handler. j += 2; } sentence += " " + cal.getTime(); } for (int i = 0; i < s.length; i++) { System.out.println(s[i]); } }// end of try block catch (ArrayIndexOutOfBoundsException e) { System.out.println(e); }// end of catch block
}
} }
|