webApp1/src/main/java/usuario/usuario.java
public String add_user_to_db(){
        String result = "Error when adding user to database";
        // define query
        String query = "insert into users(\"FIRST_NAME\",\"NAME\",\"EMAIL\",\"USERNAME\",\"PASSWORD\") values(?,?,?,?,?)";
        Connection c = null;
        try{
            // create a database connection
            Class.forName("org.apache.derby.jdbc.ClientDriver");           
            c = DriverManager.getConnection("jdbc:derby://localhost:1527/isdcm_lab_db;user=isdcm_lab_db;password=isdcm_lab_db");
            
            // prepare statement
            PreparedStatement statement;
            statement = c.prepareStatement(query);
            statement.setString(1,this.getNombre());
            statement.setString(2,this.getApellidos());
            statement.setString(3,this.getEmail());
            statement.setString(4,this.getApodo());
            statement.setString(5,this.getContrasena());
            
            // execute query
            int i = statement.executeUpdate();
            result = "User successfully added to database";
        }catch (ClassNotFoundException | SQLException e) {
            System.out.println(Arrays.toString(e.getStackTrace()));
        }finally {
            try {
                if (c != null) 
                    c.close();                
            } catch (SQLException e) {
                System.out.println(Arrays.toString(e.getStackTrace()));
            }
        }
        return result;
    }
//add a user to the db
add a user to the db
add a user to the db
public String add_user_to_db(){
        String result = "Error when adding user to database";
        String query = "insert into users(\"FIRST_NAME\",\"NAME\",\"EMAIL\",\"USERNAME\",\"PASSWORD\") values(?,?,?,?,?)";
        Connection c = null;
        try{
            Class.forName("org.apache.derby.jdbc.ClientDriver");           
            c = DriverManager.getConnection("jdbc:derby://localhost:1527/isdcm_lab_db;user=isdcm_lab_db;password=isdcm_lab_db");
            PreparedStatement statement;
            statement = c.prepareStatement(query);
            statement.setString(1,this.getNombre());
            statement.setString(2,this.getApellidos());
            statement.setString(3,this.getEmail());
            statement.setString(4,this.getApodo());
            statement.setString(5,this.getContrasena());
            int i = statement.executeUpdate();
            result = "User successfully added to database";
        }catch (ClassNotFoundException | SQLException e) {
            System.out.println(Arrays.toString(e.getStackTrace()));
        }finally {
            try {
                if (c != null) 
                    c.close();                
            } catch (SQLException e) {
                System.out.println(Arrays.toString(e.getStackTrace()));
            }
        }
        return result;
    }
public String add_user_to_db ( ) { String result = "Error when adding user to database" ; String query = "insert into users(\"FIRST_NAME\",\"NAME\",\"EMAIL\",\"USERNAME\",\"PASSWORD\") values(?,?,?,?,?)" ; Connection c = null ; try { Class . forName ( "org.apache.derby.jdbc.ClientDriver" ) ; c = DriverManager . getConnection ( "jdbc:derby://localhost:1527/isdcm_lab_db;user=isdcm_lab_db;password=isdcm_lab_db" ) ; PreparedStatement statement ; statement = c . prepareStatement ( query ) ; statement . setString ( 1 , this . getNombre ( ) ) ; statement . setString ( 2 , this . getApellidos ( ) ) ; statement . setString ( 3 , this . getEmail ( ) ) ; statement . setString ( 4 , this . getApodo ( ) ) ; statement . setString ( 5 , this . getContrasena ( ) ) ; int i = statement . executeUpdate ( ) ; result = "User successfully added to database" ; } catch ( ClassNotFoundException | SQLException e ) { System . out . println ( Arrays . toString ( e . getStackTrace ( ) ) ) ; } finally { try { if ( c != null ) c . close ( ) ; } catch ( SQLException e ) { System . out . println ( Arrays . toString ( e . getStackTrace ( ) ) ) ; } } return result ; }
add a user to the db
add a user to the db
// define query // create a database connection // prepare statement // execute query