Posts by Felipe Marinho • 2,873 points
108 posts
-
2
votes1
answer290
viewsA: Pick only numbers from a String (Tokenizer)
There are two errors, the first is that you are consuming the token during the if and is not storing its value. The second is that you are passing as argument to the method Integer.parseInt the…
-
1
votes1
answer110
viewsA: list to store objects
It depends on what features you want in your collection. Basically the differences between a Set<T> and a List<T> sane: A List<T> accepts duplicate elements, already a Set<T>…
javaanswered Felipe Marinho 2,873 -
7
votes2
answers820
viewsA: What is type and state inheritance?
Type inheritance Type inheritance is the ability of a class to inherit a interface (interface - in this context - does not necessarily mean something that makes use of keyword interface, but rather…
-
0
votes1
answer69
viewsA: Buble Sort Arraylist - Java
You can implement a Comparator with the sort rules you want and then use the method Collections.sort. Example: List<String> arrayCapacitacaoAux = new ArrayList<>();…
-
0
votes2
answers117
viewsA: Problem when calculating time
You reversed the formula, 3 is the divisor and not the dividend. The correct formula of the volume of a sphere is (4 * 3.14 * Math.pow(raio, 3)) / 3. In addition, the class Math has a constant for…
javaanswered Felipe Marinho 2,873 -
2
votes1
answer1621
viewsA: regex java replace all
You need to do the escape of the keys. String url = "/users/{id}/books/{id_book}"; url = url.replaceAll("\\{\\w*\\}", "\\\\w*"); System.out.println("result url:" + url);…
-
3
votes3
answers950
viewsA: How to limit the characters of a label?
Java Servlet 3.0 or higher If you are using Java Servlet version 3.0 or higher you can use this code snippet: <lable><c:out value="${anuncio.getTitulo().length() <= maxSize ?…
-
1
votes2
answers928
viewsA: Java Rest Client Receiving a Localdate
Change the dependency version jackson-datatype-jsr310 for the same version of the dependency jackson-databind: <dependency> <groupId>com.fasterxml.jackson.core</groupId>…
-
0
votes1
answer242
viewsA: How to compare two List<Float> in Junit?
Use the methods assertThat class MatcherAssert and the method is class CoreMatchers. Example: @Test public void verificaSeAListaASerTestadaEIgualAEsperada() { List<Float> listaASerTestada =…
-
1
votes2
answers939
viewsA: Use foreign key as primary key - Hibernate
Try to use the annotation @Mapsid thus: @Entity public class Estoque { @Id private int id; @MapsId("id") @OneToOne(cascade=CascadeType.ALL) @JoinColumn(name="id", referencedColumnName="idLivro")…
-
2
votes7
answers185
viewsA: Capture year outside the regex
Test the following regular expression to see if a date is valid: EMISSAO=\"([0-9]{4,}(?<=0*2(0(1[8-9]|[2-9][0-9])|[1-9][0-9]{2})|[3-9][0-9]{3}))-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])…
-
1
votes2
answers138
viewsA: Stream Manipulation(java 8)
You can use the method map. Stream<String[]> linhasSemPipe = Files.lines(caminho,StandardCharsets.ISO_8859_1) .map(linha -> linha.split("\\|"));…
-
0
votes1
answer954
viewsA: Manytomany mapping with additional column
You need to create an entity PartidaJogador with a composite primary key referencing the entities' keys Partida and Jogador. Example: Change the relationship in the table Partida for:…
-
1
votes2
answers174
viewsA: How to load persistence.xml settings in Combopooleddatasource?
Correct properties: Change that: <property name="hibernate.c3p0.minPoolSize" value="10"/> <property name="hibernate.c3p0.maxPoolSize" value="20"/> To: <property…
-
1
votes1
answer32
viewsA: To use Hibernatestatistics is required to create a Hibernate.cfg.xml?
From JPA 2.1 you can recover the SessionFactory as follows: SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
-
1
votes1
answer133
viewsA: Printstream does not record accents
This problem is not caused by Character encoding of PrintScream, but by using different Character encodings between the Scanner and the console/terminal you are using. To solve this problem you can…
-
1
votes1
answer847
viewsA: @Queryparam - Type Date
According to the jersey documentation, for a class to be supported as a @QueryParam, it needs to meet the following requirements: To be a primitive kind; Has a builder that accepts only one String…
javaanswered Felipe Marinho 2,873 -
1
votes2
answers55
viewsA: switch not recognizing ENUM as constant
A value used in a case needs to be a Constant variable, that is, a variable final of a primitive type or String initialized at compile time, or a enum. This is not the case for the value returned by…
javaanswered Felipe Marinho 2,873 -
0
votes1
answer2056
viewsA: org.hibernate.Queryexception: could not resolve Property: Request of: Classes.Client
Queries made in HQL or JPQL have as reference the name of its classes, attributes and the relationship between them. Based on the relationship expressed in your mapping the query should be done this…
-
0
votes6
answers615
viewsA: Regular Expressions with Java Patterns
Try the following: Pattern pattern = Pattern.compile("(?=^[.[^a]]*?a[.[^a]]*?a[.[^a]]*?$)^.*?b.*?b.*$"); //Use o find ou invés de matches System.out.println(pattern.matcher("abdbbbabd").find());…
-
1
votes1
answer269
viewsA: Pass variable from daughter page to parent page in jsp
Declare your c:import as a variable somewhere before where you are using the attributetitle. Example: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>…
-
0
votes1
answer221
viewsA: Java Sftp upload method never ends
According to the example on the library website, you need to disconnect from the session using the method disconnect class Session. public void Upload(String localfile) { String SFTPHOST =…
-
1
votes1
answer561
viewsA: Using enums in java
I don’t recommend using the ordinal enum as her identifier in the database. If you do this, adding a new element in the enumeration that is not at the end or reordering them will generate an…
-
0
votes1
answer118
viewsA: Hibernate - Set foreign key object without seeking object. Direct by Id
If you know that the entity already exists in the database, you can use the method getReference of EntityManager. Using this method, Hibernate will not fetch the entity in the database, it will just…
-
3
votes2
answers172
viewsA: Is it possible to copy directory names without copying their contents?
The following method copies all direct child files from a source folder to a destination folder: public static final List<File> copiarSubdiretorios(File origem, File destino) throws…
-
2
votes1
answer539
viewsA: JPA-HIBERNATE : I understood the conjunctions and disjunctions ? Is that right?
SQL operators follow the following order of precedence: NOT > AND > OR. That is, expressions with the operator are first evaluated NOT, next AND and finally OR . Thus, the consultation: WHERE…
-
1
votes1
answer409
viewsA: Angular, Java Service REST
You need to add the annotation @Consumes(MediaType.APPLICATION_JSON): @POST @Path("/insert") @Consumes(MediaType.APPLICATION_JSON) public void inserirCurso(Curso c){ new CtrlCurso().insert(c); }…
-
2
votes1
answer245
viewsA: Java RESTFULL using Jersey
You’re mixing Jersey versions 1.x and 2.x settings in your web.xml. The following property belongs to version 1.x: com.sun.jersey.config.property.packages The corresponding property in version 2.x…
-
3
votes3
answers377
viewsA: Hibernate works OK, but does not finish the process
You need to close your SessionFactory using the method closethus: package testehibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import…
-
2
votes1
answer3898
viewsA: Object References an Unsaved Transient instance - save the Transient instance before Flushing
The instance usuarioModel is probably in the state Detached, JPA doesn’t know who she is because she’s out of the Persistence Context. In the stretch: //Salvar Insert Id do Objeto Usuário para a…
-
1
votes2
answers57
viewsA: How to make a select that returns the expected result
As said by Marcelo Bonifazio, ideal would be to have a column indicating the upload date of the video. As there is, I will assume that last upload has the largest handle. SELECT c.nome, v.titulo,…
-
3
votes1
answer404
viewsA: The import org.springframework.web.bind.Annotation.Crossorigin cannot be resolved
The @Crossorigin annotation was added to Spring in version 4.2 and you are using the version 4.0.6.RELEASE. Change your version to the latest version of Spring 4.3.6.RELEASE and that will solve the…
-
2
votes1
answer3383
viewsA: Upload and download image to project folder using Spring Boot
Create a method that receives the name of an image and download it, example: @Controller @EnableAutoConfiguration public class Main { @Autowired private ServletContext servletContext; //Lista as…
-
2
votes1
answer1312
viewsA: Pass variable between javafx windows
This is because you are setting the controller in your file fxml, thus the method initialize(URL location, ResourceBundle resources) is evoked during the method call load class FXMLLoader. That is,…
-
4
votes1
answer46
viewsA: Error Parameter 5
You did not inject the fifth parameter of your query. Instead, you placed the third parameter twice. Replace that: pst.setString(1, txt_nome.getText()); pst.setString(2, txt_telefone.getText());…
-
1
votes1
answer180
viewsA: Bug in Spring with Hibernate query code
To NullPointerException is occurring because you are manually instantiating the classes ContactService and ContactDAO, so Spring doesn’t inject the EntityManager. Change these snippets of code to:…
-
3
votes2
answers558
viewsA: Sort by the number of repetitions in a column?
Assuming you have two tables, one for books and one for comments, you could do so: Table livro: CREATE TABLE livro ( id INT, nome VARCHAR(25), PRIMARY KEY(id) ) INSERT INTO livro VALUES(1, "livro…
-
0
votes1
answer144
viewsA: Unmarked class
Change that: <mainClass>com.roknauta.addOption.src.main.java.addOptions.Main</mainClass> To: <mainClass>appOptions.Main</mainClass>…
-
0
votes1
answer114
viewsA: Doubt about threads
Watchservice You can create a Watchservice to notify you whenever an event occurs in the directory you are observing. Example: public class WatchServiceTest { public static void main(String[] args)…
-
0
votes2
answers267
viewsA: 404 in css file after spring mapping
The problem is that you are mapping the file to a folder called resources inside the briefcase src/main/webapp(which is the place indicated for these acquisitions), but is putting the files in the…
-
4
votes3
answers196
viewsA: Remove from Integer List
The interface List<Integer> Java has 2 methods remove: Integer java.util.List.remove(int index): removes the element from the list in the index (index) specified. If it exists, the value no…
-
1
votes2
answers549
viewsA: Removing replaceAll("[().- "]")
The class String in Java is immutable. This means that its value does not change after its creation. When you call the method replaceAll(String regex, String replacement), a new String is returned…
-
2
votes1
answer123
viewsA: Error in adding foreign key
According to the section on foreign key in the Mysql documentation: Innodb allows a foreign key to reference any column or group of columns. However, in the referenced table, there must be an index…
-
17
votes3
answers1013
viewsA: Contains in Java, how to search a text in an Arraylist?
List<String> list = new ArrayList<>(); list.add("Paulo"); list.add("Adriano"); list.add("Paula"); List<String> resultado = list.stream() .filter(s -> s.contains("Pa"))…
javaanswered Felipe Marinho 2,873 -
1
votes1
answer1115
viewsA: How can I take values from selected checkboxes and send as a List to Spring MVC?
Just use the annotation @RequestParam and enter the name of the parameter, which in its case is the field value name in the input type="checkbox". //Altere o value e method de acordo com o…
-
1
votes2
answers328
viewsA: What would the query look like to return values in a given range?
The problem with your query is that in this part >= DATE_ADD(CURDATE(), INTERVAL 10 DAY) you say to search for dates that are greater or equal today’s date plus 10 days, example: on 23/01/2017…
-
0
votes3
answers1781
viewsA: How to validate a double field?
The problem is in this part: private void B_CadastrarActionPerformed(java.awt.event.ActionEvent evt) { capturaBeans(); // se for true entra no if if(cardapioC.verificaDados(cardapioB,…
-
1
votes1
answer145
viewsA: Spring MVC validation error in nested Entity
In Entity Escola that you placed there is an attribute Endereco. You forgot to put it? If there is an address attribute in the class Escola, add the annotation @Valid: @NotNull @Valid private…
-
1
votes1
answer663
viewsA: Method call within JSP
Some remarks: How are you adding your vendor list as a àttribute your request in that passage: request.setAttribute("listaFornecedores", listaFornecedores); The following code snippet in your JSP…
-
1
votes2
answers1484
viewsA: How to Configure Text Editor for git
git config --global core.editor "subl -n -w" Source Note: If sublime has not been added to your environment variables, you need to inform the full path to the app instead of just subl. Example: git…