Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Remote EJB MySql query does not work with hibernate - No suitable driver found for jdbc
- /**
- * Session Bean implementation class HelloWorldBean
- */
- @Stateless(mappedName="HelloWorldBean")
- @Remote(HelloWorldBeanRemote.class)
- public class HelloWorldBean implements HelloWorldBeanRemote
- {
- public HelloWorldBean() {}
- @Override
- public String getHelloWorld(String name)
- {
- String ret = "";
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=name&password=pwd");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM test.lang");
- while(rs.next())
- ret += rs.getString("text");
- return ret += "hello world";
- }
- }
- /**
- * Session Bean implementation class HelloWorldBean
- */
- @Stateless(mappedName="HelloWorldBean")
- @Remote(HelloWorldBeanRemote.class)
- public class HelloWorldBean implements HelloWorldBeanRemote
- {
- public HelloWorldBean() {}
- @Override
- public String getHelloWorld(String name)
- {
- String ret = "";
- /*
- * SessionFactory is bound to jndi via hibernate.cfg.xml
- * SessionManagement is a simple class which manages my
- * Hibernate Session, just pass through methods
- */
- SessionManagement.initSessionFactory();
- Session session = SessionManagement.openSession();
- List<Lang> listLang = session.createQuery("from Lang").list();
- for(Lang l : listLang)
- ret += l.getText();
- session.close();
- return ret += "hello world";
- }
- }
- Exception in thread "main" javax.ejb.EJBException: org.hibernate.exception.JDBCConnectionException: Cannot open connection
- ...
- ...
- Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/store24
Add Comment
Please, Sign In to add comment