我已经将oracle连接到我的Java程序,并且它工作正常但它在主键字段上出现问题,当我尝试访问它时会抛出java.sql.SQLException:
select user_id
from users
where users.user_name = '"+username+"'
and `users.user_role = (select user_roles.role_id FROM user_roles where `user_roles.role_name = '"+role+"')"
Run Code Online (Sandbox Code Playgroud)
在sqlDeveloper中运行时,查询有效.
这是代码:
Statement st = null;
ResultSet rs = null;
Integer userMovedTo = new Integer(0) ;
Integer userMovedBy = new Integer(0);
try {
st = conn.createStatement();
rs = st.executeQuery(query);
userMovedTo = rs.getInt("USER_ID");
Run Code Online (Sandbox Code Playgroud)
它给出异常并且不识别该字段USER_ID.
USERS 表格和顺序:
CREATE TABLE Users(
user_ID INT NOT NULL,
user_name VARCHAR (20) NOT NULL,
user_password VARCHAR (20) NOT NULL,
user_role INT NOT NULL, …Run Code Online (Sandbox Code Playgroud) 我有一个具体的问题.我有一个包含无效值的表.我需要用0大于的前一个值替换无效值(此处)0.
困难在于,对我来说使用Update或插入是不合适的(Cursor和update会这样做).我唯一的方法是使用Select语句.
当我lag(col1, 1)在大小写时使用- 函数时,我只得到一个具有正确值的列.
select col1, col2 realcol2,
(case
when col2 = 0 then
lag(col2,1,1) over (partition by col1 order by col1 )
else
col2
end ) col2,
col3 realcol3,
(case
when col3 = 0 then
lag(col3,1,1) over (partition by col1 order by col1 )
else
col3
end ) col3
from test_table
Run Code Online (Sandbox Code Playgroud)
内容TEST_TABLE:
---------------------------
Col1 | Col2 | Col3 | Col4
---------------------------
A | 0 | 1 | 5
B | …Run Code Online (Sandbox Code Playgroud) 我正在尝试从Camel中的路由中删除一些样板.
例如,让我们考虑两条相似的路线,并且可以生成大部分内部东西.我创建了一个组件"模板",它创建TemplateEndpoint并修改了XML配置以使用模板组件.
TemplateEndpoint.generateRoute从StartupListener(定义中TemplateEndpoint.setSuffix)调用自定义方法(添加路由定义).因此,当Camel上下文启动时,路由定义出现在上下文中,但框架不会为它们创建路由服务,因此它们不会启动.
如何开始添加路线StartupListener?
可能我正面临一个XY问题,你可以建议我一个更好的方法来做这个技巧(即动态添加和启动路线).
类似的两条路线
<route id="route_A">
<from uri="restlet:/another1?restletMethods=GET" />
<to uri="first:run_A" />
<to uri="second:jump_A" />
<to uri="third:fly_A" />
</route>
<route id="route_B">
<from uri="restlet:/another2?restletMethods=GET" />
<to uri="first:run_B" />
<to uri="second:jump_B" />
<to uri="third:fly_B" />
</route>
Run Code Online (Sandbox Code Playgroud)
修改过的XML
<route id="route_A">
<from uri="restlet:/another1?restletMethods=GET" />
<to uri="template://?suffix=A" />
</route>
<route id="route_B">
<from uri="restlet:/another2?restletMethods=GET" />
<to uri="template://?suffix=B" />
</route>
Run Code Online (Sandbox Code Playgroud)
端点
public class TemplateEndpoint extends DefaultEndpoint {
/* some methods omitted */
// this endpoint …Run Code Online (Sandbox Code Playgroud) 我的项目是一个SpringBoot应用程序,其中包含一个java模块。该模块没有open任何包。
模块信息.java
module my.somewhere
{
requires spring.core;
requires spring.context;
requires spring.boot;
// and so on
}
Run Code Online (Sandbox Code Playgroud)
从命令行调用时,应用程序按预期运行mvn clean spring-boot:run。
但是当我尝试从 SpringBootApplication 的 main 方法启动它时,控制台中出现以下错误:(java.lang.IllegalAccessException: module my.somewhere does not open my.somewhere.abc to module spring.core请参阅下面的详细堆栈)。
由于其反射操作,向 Spring 开放一些东西看起来很合理,但我想知道为什么 Maven 能够毫无问题地运行它。
请帮助我了解如何使应用程序以类似的方式Maven 3.6.1运行IntelliJ IDEA 2019.3。
详细堆栈:
org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessException-->module my.somewhere does not open my.somewhere.abc to module spring.core
at spring.core@5.2.4.RELEASE/org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:514) ~[spring-core-5.2.4.RELEASE.jar:na]
at spring.core@5.2.4.RELEASE/org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.2.4.RELEASE.jar:na]
at spring.core@5.2.4.RELEASE/org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.2.4.RELEASE.jar:na]
at spring.core@5.2.4.RELEASE/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.2.4.RELEASE.jar:na]
at spring.core@5.2.4.RELEASE/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.2.4.RELEASE.jar:na]
at spring.core@5.2.4.RELEASE/org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) …Run Code Online (Sandbox Code Playgroud) intellij-idea maven-3 spring-boot spring-boot-maven-plugin java-11
CREATE OR REPLACE TYPE ty_1 AS OBJECT ( fn VARCHAR2(100),
sl NUMBER,
hd DATE );
CREATE OR REPLACE TYPE ty_1_table AS TABLE OF ty_1;
CREATE OR REPLACE FUNCTION FN_RET_COL
RETURN ty_1_table
AS
c ty_1_table := TY_1_TABLE();
BEGIN
c.extend;
C(1) := TY_1('A', 1, '10-JUN-2013');
c.extend;
C(2) := TY_1('B', 2, '11-JUN-2013');
c.extend;
C(3) := TY_1('C', 3, '12-JUN-2013');
RETURN c;
END;
CREATE OR REPLACE FUNCTION FN_RET_PIPE RETURN ty_1_table PIPELINED IS
BEGIN
PIPE ROW (TY_1('A', 1, '10-JUN-2013'));
PIPE ROW (TY_1('B', 2, '11-JUN-2013'));
PIPE ROW …Run Code Online (Sandbox Code Playgroud) 我有两个表学生和来自学生的 studentprofilepic 'username' 是表的唯一键,它被引用为 'studentsprofilepic' 表的外键
表的 DDL 是
CREATE TABLE students (
id NUMBER,
username VARCHAR2(30),
password VARCHAR2(30),
firstname VARCHAR2(30),
lastname VARCHAR2(40),
email VARCHAR2(300),
dob VARCHAR2(20),
alt_email VARCHAR2(300),
street_address VARCHAR2(50),
address_2 VARCHAR2(50),
city VARCHAR2(30),
state VARCHAR2(30),
zip VARCHAR2(10),
country VARCHAR2(60),
telephone VARCHAR2(10),
CONSTRAINT student_id_pk PRIMARY KEY (id),
CONSTRAINT student_username_uk UNIQUE (username)
);
CREATE TABLE studentsprofilepic (
id NUMBER,
photo_id NUMBER,
photo BLOB,
PRIMARY KEY (photo_id),
FOREIGN KEY (username) REFERENCES students (username)
);
Run Code Online (Sandbox Code Playgroud) 我List在一个由鲜为人知的专有框架管理的类中有一个字段。
注释@BindMagic由框架管理,因此底层列表有时会发生变化:它可能会被重新创建或其元素可能会发生变化。
class SharedEntity{
@BindMagic // this annotation does a magic that we cannot control
private List<Map<String,Object>> values;
public boolean isChangedSincePreviousCall(){
// check if "values" have changed since the previous call of this method
}
}
Run Code Online (Sandbox Code Playgroud)
我同意这是一个糟糕的设计,但让我们假设没有可能影响它。
不时(不是在每个突变上)需要检查列表是否已更改。例如,我想用 method 来做isChangedSincePreviousCall。也许,像哈希和这样的东西会很好。但我很好奇有没有更好的方法。
检测列表是否更改的最佳做法是什么?
我想将一个通量分成两个通量,其中第一个通量具有原始通量的第一个项目,第二个将采用其余项目。
在myLogic对每个通量应用自定义转换后,我想将它们组合成一个通量,保留原始通量的顺序。
例子:
S:学生
S':申请后的学生myLogic
发射通量: s1 -> s2 -> s3 -> s4
第一个分裂通量: s1' => myLogic
第二个分裂通量:s2' -> s3' -> s4' => myLogic
组合通量: s1' -> s2' -> s3' -> s4'
在下面的示例中查看泛型类型的类型推断,我不能说为什么methodAutoTypeInference工作正常,但是methodNotCompilable(几乎相同)无法编译和管理它,编译器需要额外的技巧,如methodWorkaroundTypeHint或methodWorkaroundTypeCast。
什么是问题methodNotCompilable从而使编译器不能确定该表达式类型和方法的结果类型兼容?
Stream<CharSequence> methodAutoTypeInference() {
return Stream.of("a");
}
Stream<CharSequence> methodNotCompilable() {
return Stream.of("a").distinct();
// incompatible types: java.util.stream.Stream<java.lang.String>
// cannot be converted to java.util.stream.Stream<java.lang.CharSequence>
}
Stream<CharSequence> methodWorkaroundTypeHint() {
return Stream.<CharSequence>of("a").distinct();
}
Stream<CharSequence> methodWorkaroundTypeCast() {
return Stream.of((CharSequence) "a").distinct();
}
Run Code Online (Sandbox Code Playgroud) 假设我们有一个函数
suspend fun doSomething(value: Int): String {
delay(1000L)
return "abc_$value"
}
Run Code Online (Sandbox Code Playgroud)
如何将其转换为返回的函数Mono?在属于协程范围的线程和反应器事件循环线程之间切换是否存在任何隐藏问题?
fun resultAsMono(fn: suspend (Int) -> String): (Int) -> Mono<String> {
// ???
}
Run Code Online (Sandbox Code Playgroud)
那么效果会是这样的:
val newFn = resultAsMono(::doSomething)
val result = newFn(5).block()
assertThat(result).isEqualTo("abc_5")
Run Code Online (Sandbox Code Playgroud) java ×5
oracle ×4
spring-boot ×2
sql ×2
apache-camel ×1
boilerplate ×1
compilation ×1
foreign-keys ×1
generics ×1
hash ×1
java-11 ×1
kotlin ×1
maven-3 ×1
mutable ×1
plsql ×1
primary-key ×1
routes ×1
sqlexception ×1
suspend ×1
templates ×1
unique-key ×1