我想有一个存储过程,它将行插入一个表(从另一个表中的select查询中检索),并为每个新插入的行获取其标识并使用标识更新原始表
伪代码 -
records = select id,city,state,country from USER where name=@name
for each record in records // for each rows selected
insert into LOCATION(city,state,country) values(@record.city,@record.state,@record.country); //inserts a value into LOCATION table
@id = SCOPE_IDENTITY(); // gets the identity of the newly inserted row
update USER set LocationId=@id where Id=@record.id //updates the new id back to old table's column
end
Run Code Online (Sandbox Code Playgroud)
这是一个数据迁移任务,我们希望将LOCATION与USER表隔离
提前感谢您为此主题花费的时间和精力.
在我探索的过程中ExecutorService,我遇到了一种Future.get()接受它的方法timeout.
这种方法的Java文档说
如果需要,最多等待计算完成的给定时间,然后检索其结果(如果可用).
参数:
超时等待的最长时间
单位超时参数的时间单位
根据我的理解,我们正在施加超时callable,我们提交给ExecutorService我,以便在指定的时间(超时)过后我callable会中断
但是根据下面的代码,longMethod()似乎超出了超时(2秒),我真的很难理解这一点.任何人都可以请我指出正确的道路吗?
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Timeout implements Callable<String> {
public void longMethod() {
for(int i=0; i< Integer.MAX_VALUE; i++) {
System.out.println("a");
}
}
@Override
public String call() throws Exception {
longMethod();
return "done";
}
/**
* @param args
*/
public static void main(String[] args) {
ExecutorService service = Executors.newSingleThreadExecutor();
try { …Run Code Online (Sandbox Code Playgroud) 摘自SCJP 6准备书 -
鉴于:
class CardBoard {
Short story = 200;
CardBoard go(CardBoard cb) {
cb = null;
return cb;
}
public static void main(String[] args) {
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2);
c1 = null;
// do Stuff
}
}
Run Code Online (Sandbox Code Playgroud)
当达到// doStuff时,有多少对象符合GC条件?
A. 0
B. 1
C. 2
D.编译失败
E.无法知道
F.运行时抛出异常
正确答案是C - "只有一个CardBoard对象(c1)符合条件,但它有一个相关的Short包装器对象,也符合条件."
我的问题是为什么c3不符合收藏资格?
我的想法是 -
c1.go(c2)将本地引用变量cb(它是c2的副本)设置为null,然后返回分配给c3的cb.我知道c2本身的引用变量不能在方法中修改,只能修改它背后的对象.但是在我看来,引用变量cb的副本被设置为null并分配给c3.为什么在此实例中c3未设置为返回的null?
我试图在论坛中回答这个问题而且我发现尽管equals在Employee课堂上覆盖了这个方法,但我仍然可以添加重复的元素TreeSet.
TreeSet.add(E)方法的Javadoc 说
如果指定的元素尚不存在,则将其添加到此集合中.更正式地,如果集合不包含元素e2,则将指定的元素e添加到该集合中(e == null?e2 == null:e.equals(e2)).如果此set已包含该元素,则调用将保持set不变并返回false.
这实质上意味着不会插入2个等于对象,TreeSet并且仅通过equals()包含对象的方法来确定相等性.
但是,下面的代码正在添加2个元素,Set即使它们是相等的
public class Employee implements Comparable<Employee> {
String employeeName;
int employeeId;
public Employee(String name, int id) {
this.employeeName = name;
this.employeeId = id;
}
public int compareTo(Employee emp) {
//return this.employeeName.compareTo(emp.employeeName);
return (this.employeeId - emp.employeeId);
}
@Override
public String toString() {
return ("Name is: " + employeeName + " Emp id is: " + employeeId);
} …Run Code Online (Sandbox Code Playgroud) 我试图解决多线程问题,并且我很难了解其行为.
问题是: 有2个线程同时消耗偶数和奇数.我必须介绍它们之间的线程通信,以便在自然顺序中具有"消耗".
这是我的代码
public class EvenOddDemo {
public static void main(String[] args) {
Number n = new Number();
EvenThread et = new EvenThread(n);
OddThread ot = new OddThread(n);
et.start();
ot.start();
}
}
class EvenThread extends Thread {
private Number number;
public EvenThread(Number number) {
this.number = number;
}
@Override
public void run() {
for(int i=0; i<5; i++) {
System.out.println(number.getEven());
}
}
}
class OddThread extends Thread {
private Number number;
public …Run Code Online (Sandbox Code Playgroud) 我有一个任务是设计一个具有多选功能的ComboBox(GXT)大小控件.我尝试使用ComboBox的setView设置CheckBoxListView,但似乎没有工作.任何人都可以指导我,如果有任何方式使用GXT框架我可以实现这一目标吗?
PS:我在sencha论坛(java类,源代码)中找到了一个名为XComboBox的组件,它运行良好,但不能用作GNU GPL许可证
提前致谢!
我有一个任务是将存储在我的某个DB(Sql Server)表的列上的时间转换为指定的时区.该列始终包含UTC时区的时间.
我面临的问题是,当hibernate 读取列并将其设置为我的实体类时,它会在应用程序服务器的时区中设置时间.
例如:如果DB具有值 - 07 Jul 2012 10:30(实际上是UTC),则hibernate将映射的日期字段设置为07 Jul 2012 10:30 PST(假设JVM在PST运行).
现在,如果这个日期被转换为任何其他时区..说GMT + 5:30,我得到意想不到的结果
为了解决上述问题......我编写了以下代码
//Reading the DB time (which does not have timezone info)
Date dbDate = entityObj.getDBUtcDate();
//Setting GMT timezone to the date, without modifying the date
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
c.set(dbDate.getYear(), dbDate.getMonth(), dbDate.getDate()..., dbDate.getMinutes());
Date utcDate = c.getTime();
Run Code Online (Sandbox Code Playgroud)
使用上面的代码..我可以将数据库存储日期恢复为UTC时区,但是当我使用以下逻辑转换到其他时区(比如GMT + 5:30)时
Calendar outCal = Calendar.getInstance(TimeZone.getTimeZone("GMT+5:30"));
outCal.setTimeInMillis(utcDate.getTime());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, outCal.get(Calendar.YEAR));
cal.set(Calendar.MONTH, outCal.get(Calendar.MONTH));
cal.set(Calendar.DAY_OF_MONTH, outCal.get(Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR_OF_DAY, outCal.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, …Run Code Online (Sandbox Code Playgroud) 请帮我模式匹配.我想构建一个模式,该模式将匹配字符串中以j-或c-以下开头的单词(比如说)
[j-test] is a [c-test]'s name with [foo] and [bar]
Run Code Online (Sandbox Code Playgroud)
模式需要找到[j-test]和[c-test](括号包括在内).
String template = "[j-test] is a [c-test]'s name with [foo] and [bar]";
Pattern patt = Pattern.compile("\\[[*[j|c]\\-\\w\\-\\+\\d]+\\]");
Matcher m = patt.matcher(template);
while (m.find()) {
System.out.println(m.group());
}
Run Code Online (Sandbox Code Playgroud)
它的输出就像
[j-test]
[c-test]
[foo]
[bar]
Run Code Online (Sandbox Code Playgroud)
这是错的.请帮帮我,谢谢你在这个帖子上的时间.
所以继承我的问题.我有两个类... SingularEntity和ListEntity.顾名思义,SingularEntity表示一个实体,ListEntity表示一个奇异实体列表......该列表显然具有比SingularEntity本身更常见的属性.所以我有一个AuthorizationEntity扩展了SingularEntity类
public class SingularEntity{
}
public class AuthorizationEntity extends SingularEntity{
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个ListEntity,它代表任何SingularEntities的List
public class ListEntity{
public List<? extends SingularEntity> data;
public ListEntity(List<? extends SingularEntity> data){
this.data = data;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我想使用反射来总是填充列表....我总是在results.add方法中遇到错误.说方法List.add(CAP#1)不适用.任何帮助都很高兴
public List<? extends SingularEntity> build() {
List<? extends SingularEntity> results = new ArrayList<SingularEntity>();
try {
Constructor javaBeanClassConstructor =
(Constructor) DTOClass.getDeclaredConstructors()[0];
Class<?>[] constructorParameterTypes =
javaBeanClassConstructor.getParameterTypes();
for (Object[] columns : lstInput) {
Object[] constructorArgs = new Object[constructorParameterTypes.length];
for (int j = 0; j < columns.length; j++) {
Object columnValue = …Run Code Online (Sandbox Code Playgroud) java ×7
collections ×1
combobox ×1
concurrency ×1
date ×1
generics ×1
gwt ×1
gxt ×1
hibernate ×1
jdbc ×1
reflection ×1
regex ×1
scjp ×1
sql-server ×1
timezone ×1
treeset ×1