鉴于toString()下面的两个实现,首选哪一个:
public String toString(){
return "{a:"+ a + ", b:" + b + ", c: " + c +"}";
}
Run Code Online (Sandbox Code Playgroud)
要么
public String toString(){
StringBuilder sb = new StringBuilder(100);
return sb.append("{a:").append(a)
.append(", b:").append(b)
.append(", c:").append(c)
.append("}")
.toString();
}
Run Code Online (Sandbox Code Playgroud)
?
更重要的是,鉴于我们只有3个属性,它可能没有什么区别,但你会在什么时候从+concat 切换到 StringBuilder?
这是我的PostgreSQL函数:
salvarArquivoGeometricoCasoZeroPOINT
(dimensao text,tableName text,tuplas text[],srid text)
Run Code Online (Sandbox Code Playgroud)
它有一个text[]参数,我想String[]从我的JPQL 传递一个Java :
public String salvarGeometriaCaso0(String[] tuplas,FileDto arquivo){
Query query =
em().createNativeQuery("select
salvarArquivoGeometricoCasoZeroPOINT(?1,?2,?3,?4)");
query.setParameter(1,arquivo.getGeo());//String
query.setParameter(2,arquivo.getTable());/String
query.setParameter(3,tuplas);//String[]
query.setParameter(4,arquivo.getSrid());//String
return (String) query.getSingleResult();//function returns a Text, so cast to String
}
Run Code Online (Sandbox Code Playgroud)
上面的代码失败,但有异常:
ERROR] Internal Exception: org.postgresql.util.PSQLException: Can not infer a SQL
type to use for an instance of [Ljava.lang.String;.
Use setObject () with an explicit Types value to specify the type to use.
Run Code Online (Sandbox Code Playgroud)
所以我不确定如何从EclipseLink调用我的函数.
我正在使用 Spring JdbcTemplate,并且我陷入了一个查询,该查询更新实际上是一个 int 数组的列。数据库是postgres 8.3.7。这是我正在使用的代码:
public int setUsersArray(int idUser, int idDevice, Collection<Integer> ids) {
int update = -666;
int[] tipi = new int[3];
tipi[0] = java.sql.Types.INTEGER;
tipi[1] = java.sql.Types.INTEGER;
tipi[2] = java.sql.Types.ARRAY;
try {
update = this.jdbcTemplate.update(setUsersArrayQuery, new Object[] {
ids, idUser, idDevice }, tipi);
} catch (Exception e) {
e.printStackTrace();
}
return update;
}
Run Code Online (Sandbox Code Playgroud)
查询是“update table_name set array_column = ? where id_user = ? and id_device = ?”。我得到这个例外:
org.springframework.dao.DataIntegrityViolationException:PreparedStatementCallback;SQL [更新acotel_msp.users_mau 设置denied_sub_client = ? 其中 id_users = ? 和 …
java ×2
postgresql ×2
arrays ×1
eclipselink ×1
jdbctemplate ×1
jpql ×1
performance ×1
spring ×1
string ×1