facebook

change user and password to connect db using hibernate

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #256358 Reply

    gvaldez
    Member

    Hi, i have this problem, i want to connect to database using differents users name and password, i try to chage it at run time with this code:

    Properties prop = cfg.getProperties();
    prop.put(“hibernate.connection.password”,pass);
    prop.put(“hibernate.connection.username”,usr);
    cfg.getProperties().clear();
    cfg.setProperties(prop);
    sessionFactory = cfg.buildSessionFactory();

    but when sessionFactory is created it still have the old user name and pass (same in hibernate.cfg.xml)

    Please someone help me.

    #256368 Reply

    Haris Peco
    Member

    Gvaldez,

    Try this:

    cfg.setProperty(“hibernate.connection.password”,pass);
    cfg.setProperty(“hibernate.connection.username”,usr);
    sessionFactory = cfg.buildSessionFactory();

    Best

    #256370 Reply

    gvaldez
    Member

    it doesnt work, now i have this error

    org.hibernate.HibernateException: database product name cannot be null
    at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
    at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:374)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
    at mapeo.HibernateSessionFactory.nuevaConfiguracion(HibernateSessionFactory.java:113)
    at prueba.TestConexion.main(TestConexion.java:68)
    Exception in thread “main” java.lang.RuntimeException: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at mapeo.Entity.findAll(Entity.java:62)
    at prueba.TestConexion.main(TestConexion.java:71)
    Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    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:301)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
    at org.hibernate.loader.Loader.doQuery(Loader.java:390)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
    at org.hibernate.loader.Loader.doList(Loader.java:1593)
    at org.hibernate.loader.Loader.list(Loader.java:1577)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
    at mapeo.Entity.findAll(Entity.java:59)
    … 1 more
    Caused by: java.sql.SQLException: argumentos no válidos en la llamada
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
    at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:184)
    at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:365)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:547)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:347)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:140)
    at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298)
    … 13 more

    #256371 Reply

    Haris Peco
    Member

    You have to call configure, like this

    Configuration cfg= new Configuration();
    cfg.configure();
    cfg.setProperty(“hibernate.connection.password”,pass);
    cfg.setProperty(“hibernate.connection.username”,usr);
    sessionFactory = cfg.buildSessionFactory();

    and hibernate.cfg.xml must exists for other properties and mappings

    Best

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: change user and password to connect db using hibernate

You must be logged in to post in the forum log in