Guest User

Untitled

a guest
Aug 10th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. Remote EJB MySql query does not work with hibernate - No suitable driver found for jdbc
  2. /**
  3. * Session Bean implementation class HelloWorldBean
  4. */
  5. @Stateless(mappedName="HelloWorldBean")
  6. @Remote(HelloWorldBeanRemote.class)
  7. public class HelloWorldBean implements HelloWorldBeanRemote
  8. {
  9.  
  10. public HelloWorldBean() {}
  11.  
  12. @Override
  13. public String getHelloWorld(String name)
  14. {
  15.  
  16. String ret = "";
  17.  
  18. Class.forName("com.mysql.jdbc.Driver");
  19. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=name&password=pwd");
  20. Statement stmt = con.createStatement();
  21. ResultSet rs = stmt.executeQuery("SELECT * FROM test.lang");
  22.  
  23. while(rs.next())
  24. ret += rs.getString("text");
  25.  
  26. return ret += "hello world";
  27. }
  28. }
  29.  
  30. /**
  31. * Session Bean implementation class HelloWorldBean
  32. */
  33. @Stateless(mappedName="HelloWorldBean")
  34. @Remote(HelloWorldBeanRemote.class)
  35. public class HelloWorldBean implements HelloWorldBeanRemote
  36. {
  37.  
  38. public HelloWorldBean() {}
  39.  
  40. @Override
  41. public String getHelloWorld(String name)
  42. {
  43. String ret = "";
  44.  
  45. /*
  46. * SessionFactory is bound to jndi via hibernate.cfg.xml
  47. * SessionManagement is a simple class which manages my
  48. * Hibernate Session, just pass through methods
  49. */
  50. SessionManagement.initSessionFactory();
  51. Session session = SessionManagement.openSession();
  52.  
  53. List<Lang> listLang = session.createQuery("from Lang").list();
  54.  
  55. for(Lang l : listLang)
  56. ret += l.getText();
  57.  
  58. session.close();
  59.  
  60. return ret += "hello world";
  61. }
  62. }
  63.  
  64. Exception in thread "main" javax.ejb.EJBException: org.hibernate.exception.JDBCConnectionException: Cannot open connection
  65. ...
  66. ...
  67. Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/store24
Add Comment
Please, Sign In to add comment