鉴于以下Oracle sql查询为PreparedStatement:
SELECT *
FROM my_table
WHERE field1 = 'foo'
and field2 =ANY (substr( ? , 1, 2) || '00000000',
substr( ? , 1, 4) || '000000',
substr( ? , 1, 6) || '0000',
substr( ? , 1, 8) || '00',
?
)
Run Code Online (Sandbox Code Playgroud)
我想翻译成JPQL查询.阅读JPQL文档,substr变得substring
并ANY保持不变.在JPQL中ANY需要一个子查询.
如何将列表更改为子查询?或者我应该使用IN运算符还是应该生成带有一堆OR条件的JPQL字符串?
Oracle 10gR2
Java 5
JPA 2
这是我项目的Maven结构
app > common-module > webapp-module > batch-module pom.xml
该common-module公开一个Version类.webapp和批处理模块都使用此类.
该Version班有一个所谓的独特的静态方法get.它返回项目的全局版本.
全局版本存储在属性文件中.当get从批料模块(一个独立的Java应用程序)调用,属性文件成功加载.
在webapp中,情况有所不同.我创建了一个托管bean VersionBean,允许任何JSF页面调用该get方法.每当我使用以下之一时
FacesContext.getCurrentInstance().getExternalContext()
FacesContext.getCurrentInstance().getExternalContext().getContext()
Thread.currentThread().getClassLoader()
Run Code Online (Sandbox Code Playgroud)
我永远找不到properties.file.
如何从托管bean加载位于jar文件中的属性文件(getResourceAsStream)?
编辑
这是我根据@BalusC和@eljunior的建议提出的解决方案
VersionBean.java
@ManagedBean(eager=true)
@ApplicationScoped
public class VersionBean {
private String version;
@PostConstruct
public void init(){
version = Version.get();
}
}
Run Code Online (Sandbox Code Playgroud)
Version.java
public class Version {
public static String get() {
InputStream is = Version.class.getResourceAsStream("/version.properties");
// Read InputStream and return version string ...
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个博客,我想在MAIN页面上显示ADS或特殊文本,但不在任何其他带有URI的页面上显示/?paged=[number].我已经尝试过标准正则表达式,/^[0-9].$/但它无法匹配.
我不确定我做错了什么或怎么做这个
if (substr_count($_SERVER[REQUEST_URI], "/") > 0 AND
substr_count($_SERVER[REQUEST_URI], "/?paged=1") == 0 AND
substr_count($_SERVER[REQUEST_URI], "/?paged=2") == 0 AND
substr_count($_SERVER[REQUEST_URI], "/?paged=3") == 0 AND
substr_count($_SERVER[REQUEST_URI], "/?paged=4") == 0 AND
substr_count($_SERVER[REQUEST_URI], "/?paged=5") == 0) {
echo "display special text, banners, and other stuff";
}
Run Code Online (Sandbox Code Playgroud)
这就是我目前的做法,但我不想做成千上万的......
我正在编写测试,我想通过测试方法捕获STDOUT上发送的消息.这是我的代码:
@Test
public void testAction() throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException,
CmdLineException, IOException {
PrintStream originalSTDOUT = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
try {
System.setOut(ps);
// Call to the method that will print text to STDOUT...
ps.flush();
String batchLog = baos.toString("UTF-8");
assertTrue("Invalid exception text !", batchLog.contains("my expected text..."));
} finally {
System.setOut(originalSTDOUT);//Restore original STDOUT
originalSTDOUT.write(baos.toByteArray());// Write back to STDOUT, even if I comment this line, outputs go to STDOUT...
ps.close();
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,batchLog虽然我仍然可以读到STDOUT的预期文本,但它总是空的. …
我正在读一个我没写过的代码.我偶然发现了以下声明:
context.checking(new org.jmock.Expectations() {
{
allowing(habilitationManager).hasRole(RoleDtoEnum.ROLE_NEWS);
will(returnValue(true));
allowing(habilitationManager).hasRole(RoleDtoEnum.ROLE_STAT);
will(returnValue(true));
allowing(habilitationManager).getUser();
will(returnValue(getUserMock()));
oneOf(parametreService).getParametre(PPP);
will(returnValue(getMockPPP()));
}
});
Run Code Online (Sandbox Code Playgroud)
据我所知,第二种方法中的方法{ ... }是Expectations方法.
{ ... }?我写了一个正则表达式如下:
"^[\+]{0,1}([\#]|[\*]|[\d]){1,15}$"
总之,这与可选的"+"符号匹配,后跟最多15个字符,可能是"#","*"或数字.
但是,这意味着'+#'将匹配,这不是一个有效的结果,因为我总是需要至少一个数字.
典型的有效匹配可能是:
+1234
445678999
+#7897897
+345764756#775
Run Code Online (Sandbox Code Playgroud)
所以,鉴于我已经为这些匹配制作了一个有效的RegEx,我想优雅的解决方案是使用这个正则表达式并添加一些特殊标准来全局检查结果中的数字或以某种方式禁止任何没有的数据最少一位数.
我如何检查该数字?
我安装了两个 postgresql(s),9.5 应该使用端口 5433,9.3.4 应该使用端口 5432:
me@camb:/usr/lib/postgresql/9.5/bin$ ls -al psql
-rwxr-xr-x 1 root root 564464 Jan 7 14:54 psql
me@camb:/opt/pkgs/postgresql-9.3.4/bin$ ls -al psql
-rwxr-xr-x 1 root root 405960 Aug 5 18:52 psql
me@camb:/opt/pkgs/postgresql-9.3.4/bin$ cat /etc/group
postgres:x:200:
me@camb:/opt/pkgs/postgresql-9.3.4/bin$ groups postgres
postgres : postgres ssl-cert
Run Code Online (Sandbox Code Playgroud)
我写了一个脚本来安装 postgresql-9.5 并从 9.3.4 迁移到 9.5
问题0:postgresql-9.5无法启动成功以及为什么状态为online
安装期间的输出:
* Starting PostgreSQL 9.5 database server
* The PostgreSQL server failed to start. Please check the log output:
2016-01-19 19:41:49 UTC [16523-1] LOG: database system was shut down at …Run Code Online (Sandbox Code Playgroud) 我已经看到,在变量的原始版本和对象版本之间有以下映射:
因此,对于他们所有人而言,唯一的区别就是世界的第一个字母.我想知道为什么这条规则并不适用于INT变为整数(而不是我 NT)和用于焦炭变得性格,而不是(Ç HAR).
我不知道这是否是提出这个问题的合适地方,但我真的想知道这个选择是否有原因,即使是因为我向孩子们教java,他们经常向我提出同样的问题.
我有一个使用Jsoup和AsyncTask的工作示例,并且工作正常.我对表现不满意.加载带有文本和图像的简单列表页面需要3-6秒.
我想以某种方式提升表现......所以我偶然发现了凌空抽射.
任何人都可以解释热与jsoup使用齐射?
我用它来获取包含特定URL的doc对象:
public Document GetDocument(String site) {
Document doc = Jsoup.connect(site).timeout(600000)
.data("query", "Java")
.userAgent("Mozilla")
.get();
return doc;
}
Run Code Online (Sandbox Code Playgroud)
我想我只会用jsoup和连接/下载与volley分析数据?我使用Jsoup.connect(site).timeout(600000)我应该用齐射吗?
任何人都可以使用volley和jsoup编写/链接一个简单的例子吗?
这是我的脚本:
my_var="foo
bar
baz"
echo ${my_var//\n/\\n}
Run Code Online (Sandbox Code Playgroud)
我想用替换所有换行符\\n.
然而,这就是我所拥有的:
foo bar baz
Run Code Online (Sandbox Code Playgroud)
我错过了什么?