我试图在将其转储到数据库之前使用java验证excel文件.
这是我的代码片段,它会导致错误.
try {
fis = new FileInputStream(file);
wb = new XSSFWorkbook(fis);
XSSFSheet sh = wb.getSheet("Sheet1");
for(int i = 0 ; i < 44 ; i++){
XSSFCell a1 = sh.getRow(1).getCell(i);
printXSSFCellType(a1);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.ArrayList.<init>(Unknown Source)
at java.util.ArrayList.<init>(Unknown Source)
at org.apache.xmlbeans.impl.values.NamespaceContext$NamespaceContextStack.<init>(NamespaceContext.java:78)
at org.apache.xmlbeans.impl.values.NamespaceContext$NamespaceContextStack.<init>(NamespaceContext.java:75)
at org.apache.xmlbeans.impl.values.NamespaceContext.getNamespaceContextStack(NamespaceContext.java:98)
at org.apache.xmlbeans.impl.values.NamespaceContext.push(NamespaceContext.java:106)
at org.apache.xmlbeans.impl.values.XmlObjectBase.check_dated(XmlObjectBase.java:1273) …
Run Code Online (Sandbox Code Playgroud) 我有一个oracle查询,我试图使用jdbc执行.以下是查询.
insert into bd_vehicles_temp select * from bd_vehicles_temp_1
Run Code Online (Sandbox Code Playgroud)
table bd_vehicles_temp_1包含大约7000-10000行.如果bd_vehicles_temp_1中的主键已存在于bd_vehicles_temp中,则会得到SQLException:唯一键约束.
异常的行在pstmt.executeUpdate()
我的代码中是幕后的.有没有办法精确定位bd_vehicles_temp_1中导致异常的行.
或者我是否必须循环遍历bd_vehicles_temp_1中的行并逐行插入每一行?
提前致谢 !
这是我用来创建 DAO 对象的配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@XXX.XX.XX.XXX:XXX:XXX"/>
<property name="username" value="encryptedUsername"/>
<property name="password" value="decrytedPassword"/>
</bean>
<bean id="fiBillJDBCTemplate" class="com.tfl.fi.billing.dao.FIBillingDAOImpl">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
通常我们可以如下创建数据库对象
ApplicationContext context =
new ClassPathXmlApplicationContext("Parent.xml");
FIBillingDAOImpl dao =
(FIBillingDAOImpl)context.getBean("fiBillJDBCTemplate");
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为存储在 xml 文件中的密码是加密的。
如何制作 DAO 对象以解密密码。
public static void main(String[] args) {
File dir = new File("dir");
dir.mkdir();
File file = new File(dir,"file.txt");;;;;
;
;
;
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
;
;
;
;
}
}
Run Code Online (Sandbox Code Playgroud)
编译器显示额外的分号没有错误.并且代码运行就好像没有发生任何错误.我想知道幕后发生了什么?包括这样的分号是否会消耗更多的堆栈内存,因此需要更多的处理器周期才能运行?
我正在准备OCJP考试.我正在进行模拟测试.这是一段代码片段.
public class GC {
private Object o;
private void doSomethingElse(Object obj) {
o = obj;
}
public void doSomething() {
Object obj = new Object(); // Line 5
doSomethingElse(obj); // Line 6
obj = new Object(); // Line 7
doSomethingElse(null); // Line 8
obj = null; // Line 9
}
}
Run Code Online (Sandbox Code Playgroud)
调用doSomething方法后,Object obj可用于垃圾回收吗?
我知道答案是第9行,但根据考试模拟器它是第8行?我不确定谁是对的?
我正在将托管bean注入另一个托管bean的托管属性.
package com.books.beans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="book")
@RequestScoped
public class Book {
@ManagedProperty(value = "page")
private Page pages;
// Getter/setter
}
Run Code Online (Sandbox Code Playgroud)
package com.books.beans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="page")
@RequestScoped
public class Page {
// ...
}
Run Code Online (Sandbox Code Playgroud)
但是,它抛出以下EL异常:
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/JSFTraining] threw exception [Unable to set property pages for managed bean book] with root cause
javax.el.ELException: Cannot convert page of type class java.lang.String to class com.books.beans.Page
at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:416)
at org.apache.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:46) …
Run Code Online (Sandbox Code Playgroud) 假设 Java 8。
默认大小ArrayList
为 10(存储数据的数组大小默认为 10),当添加第 11 个元素时,数组大小增加到 15。
如果在第 11 个位置添加 null,它也会增加吗?
我知道调用size()
list 会返回11
,但问题是内部数组是否也会增长?
我观察到了这一点
$("#bank1.bankName").hide();
Run Code Online (Sandbox Code Playgroud)
不起作用
$("test").hide()
Run Code Online (Sandbox Code Playgroud)
作品
这是什么原因?什么是可能的解决方案
编辑包括标记
<td id = "bank1.bankName">
<form:input path="bankDetails[0].bankName" size = "12"/>
</td>
Run Code Online (Sandbox Code Playgroud)
我正在使用Spring MVC
我在互联网上遇到了一段代码片段.在这里
public class Test {
public static void main(String[] args) {
Random random = new Random(441287210);
for(int j=0;j<10;j++) {
System.out.print(random.nextInt(10)+" ");
}
}
}
Run Code Online (Sandbox Code Playgroud)
每次我运行它打印1 1 1 1 1 1 1 1 1 1
.这可能是有充分理由的.
为什么会出现这种行为.
这是源 - > http://www.javacodegeeks.com/2011/10/weird-funny-java.html
我有一个类定义说
class Employee {
String id;
String name;
int age;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我想用它创建一个 json 对象,如下所示
{
"id" : "A12",
"employee_name" : "Abhishek"
age : 97
}
Run Code Online (Sandbox Code Playgroud)
注意employee_name
不对应 POJO 变量name
。那么我可以添加某些注释来帮助我这样做吗?就像是
@JSONKey(value="employee_name")
String name
Run Code Online (Sandbox Code Playgroud)
给出与 GSON 和/或 Jackson 相关的解决方案。
我有一个.sql
文件,其中包含create procedure语句,后跟grant语句,如下所示.
create or replace
PROCEDURE PROCEDURE_NAME()
AS
BEGIN
.....................
END;
GRANT EXECUTE ON PROCEDURE_NAME TO ROLE_NAME;
Run Code Online (Sandbox Code Playgroud)
如果我删除授权声明一切正常.但是使用grant语句会出现以下错误.
Error(23,1): PLS-00103: Encountered the symbol "GRANT"
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?可以将grant语句包含在脚本中,就像我们在create
语句中使用它时一样吗?
java ×8
jdbc ×2
oracle ×2
apache-poi ×1
arraylist ×1
el ×1
gson ×1
jackson ×1
jquery ×1
jsf ×1
json ×1
jxl ×1
managed-bean ×1
spring-jdbc ×1
sql ×1