tengo un incovenienten , les cuento estoy creado una clase para que me haga de manager con las bases de datos es decir que me cree la conexion , que ejecutes los query o alguna actulizacion y luego cierre la conexion , el siguiente incoveniente es el que tengo , mi clase se conecta bien a la base de datos (estoy usando Auntenticacion )si fallo me da error y luego si trato ingresar con un usuario valido como quiera me da la misma excepcion(rechanzando la conexion ), estoy usando Derby pero supongo que es problema de programacion, la verdad estoy perdido. dejare el codigo a ver si me pueden hechar una mano o consejo
Código
public class RockPosDBManager { private boolean debugEnable; private int engine; private int typeOfConn; private boolean Authentication; private boolean create; private boolean isConnected; /** * @function Print * @brief this function Print Information on terminal console if the Debug Flag is enable. * @param String - this String is the value that will be print onto the screen * */ if( debugEnable == false) return; if( templ != null ) { //System.out.printf("DEBUG : %s\n", templ ); } } /** * @function Print * @brief this constructor will set the current Engine, kind of connection, we have avaliable Derby engine and Mysql . * @param int sqlEngine =type of Engine rockPosClient = server, embedded or Client * @see RockPosDBEngine & RockPosTypeConn * */ public RockPosDBManager(int sqlEngine , int rockposClient, boolean created ){ this.engine = sqlEngine; this.typeOfConn = rockposClient; this.debugEnable = false; this.isConnected = false; this.create = created; } /** * @function setDebugVerbose * @brief this function will turn on the Debug Flag for Terminal. * @param none * @see * */ public void setDebugVerbose(boolean e){ debugEnable=e; } /** * @function isConnectedIntoDatabase * @brief this Function Verify if the databe is connected; * @param none * @see * */ public boolean isConnectedIntoDatabase(){ return this.isConnected; } /** * @function SetDBNameConn * @brief * @param * @see * */ try{ if(DBname == null) this.DBName = DBname; Print("DB name is : "+ DBName); switch(engine){ case RockPosDBEngine.SQL_DERBY: Print("ENGINE SQL_DERBY"); switch(typeOfConn) { case RockPosTypeConn.ROCKPOS_CLIENT: Print("Type Of Connection ROCKPOS_CLIENT"); finalConnectionString = DerbyServer + this.DBName; finalDriver = Clientdriver; break; case RockPosTypeConn.ROCKPOS_EMBEDDED: Print("Type Of Connection ROCKPOS_EMBEDDED"); finalConnectionString = DerbyNoServer + this.DBName; finalDriver = Embeddeddriver ; break; case RockPosTypeConn.ROCKPOS_SERVER: Print("Type Of Connection ROCKPOS_SERVER"); finalConnectionString = DerbyServer + this.DBName; finalDriver = Clientdriver; break; } break; case RockPosDBEngine.SQL_MYSQL: Print("ENGINE SQL_MYSQL"); switch(typeOfConn) { case RockPosTypeConn.ROCKPOS_CLIENT: /// Print("Type Of Connection ROCKPOS_CLIENT"); finalConnectionString = MySQLServer + this.DBName; finalDriver = mySQLClientDriver; break; case RockPosTypeConn.ROCKPOS_EMBEDDED: //// Print("Type Of Connection ROCKPOS_EMBEDDED"); Print("MySQL does not work in Embedded Mode yet."); finalDriver = mySQLClientDriver; break; case RockPosTypeConn.ROCKPOS_SERVER: //// Print("Type Of Connection ROCKPOS_SERVER"); finalConnectionString = MySQLServer + this.DBName; finalDriver = mySQLClientDriver; break; } break; } Print("Connection Driver is : "+ finalDriver); Print("Connection String is ===> "+ finalConnectionString); if(this.UserName != null && this.password != null) { Print("Authentication is On."); Print("User name is =[ "+this.UserName+ " ] password = [ "+ this.password +"]"); Authentication = true; } else { Print("Authentication is On."); Print("No user name was provide."); Authentication = false; } { e.printStackTrace(); } } /** * @function SetCredential * @brief * @param * @see * */ if(user != null) this.UserName = user; if(pass != null) this.password = pass; } public void RequireAuth(boolean auth){ this.Authentication = auth; } /** * @function Connect * @brief * @param * @see * */ public boolean Connect(){ this.connection = null; try{ Class.forName(finalDriver); } { e.printStackTrace(); this.isConnected = false; return this.isConnected ; } try{ String param; if(create == false) { param = finalConnectionString +";user="+ this.UserName+";password="+ this.password; } else { param = finalConnectionString +";create=true;user="+this.UserName+";password="+ this.password; } if(this.connection.isValid(30)){ this.isConnected = true; } else{ this.isConnected = false; } } { int code = e.getErrorCode(); e.printStackTrace(); this.isConnected = false; return this.isConnected; } return this.isConnected; } public boolean Disconnect(){ try { this.connection.close(); e.printStackTrace(); return isConnected; } this.isConnected = false; return isConnected; } ///Print("Execute"); boolean res = true; if(this.isConnected == false ) { Print("theres is not Connection"); return false; } try { stmt = this.connection.prepareStatement(sql); stmt.executeUpdate(sql); e.printStackTrace(); Print("Error Executing that Query"); return false; } finally{ ///Print("Execute Finally"); try { stmt.close(); Print("Error closing Statement."); } } return res; } if(this.isConnected == false ) { Print("theres is not Connection"); return null; } try { this.connection.setAutoCommit(true); stmt = this.connection.createStatement(); result = stmt.executeQuery(sql); if(result == null) Print("Result is null"); Print("Error Executing that Query"); } try { stmt.close(); Print("Error closing Statement."); } return result; } public void CloseConn(){ try { this.connection.close(); Print("Closing Connection"); Print("Error Closing Conection."); } this.isConnected= false; } }
algo que me falto ponerle es una prueba de lo que quiero hacer
Código
RockPosDBManager rm = new RockPosDBManager(RockPosDBEngine.SQL_DERBY, RockPosTypeConn.ROCKPOS_CLIENT, true); rm.SetDBNameConn(RockPosConstant.DB_PATH+"d1234f"); rm.SetCredential("dbmanager", "dbmanager"); boolean creado = rm.Connect(); if(creado == true) else{ } String sql = "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.database.defaultConnectionMode\',\'noAccess\')"; creado = rm.Execute(sql); if(creado == true) else{ } rm.Disconnect(); rm.SetDBNameConn(RockPosConstant.DB_PATH+"d1234f"); rm.SetCredential("usuario2", "usuario2"); creado = rm.Connect(); if(creado == true) else{ } rm.Disconnect(); rm.SetCredential("dbmanager", "dbmanager"); creado = rm.Connect(); if(creado == true) else{ return; }