下面我正在创建表格.
public static final String CREATE_SQL = "CREATE TABLE " +DATABASE_TABLE +
"(ID number(10,0), " +
" CGUID VARCHAR(255), " +
" PGUID VARCHAR(255), " +
" SGUID VARCHAR(255), " +
" USERID VARCHAR(255), " +
" ULOC VARCHAR(255), " +
" SLOC VARCHAR(255), " +
" PLOC VARCHAR(255), " +
" ALOC VARCHAR(255), " +
" SITEID VARCHAR(255), " +
" ATTRIBUTEID VARCHAR(255), " +
" ATTRIBUTEVALUE VARCHAR(255), " +
" PRIMARY KEY ( ID ))";
Run Code Online (Sandbox Code Playgroud)
当我尝试更新我的数据库表时,这是以下UPSERT_SQL查询我总是得到 - java.sql.SQLException:ORA-00936:缺少表达式 …
我实际上是在尝试实现一个链接列表,它使用java来移动列表中的所有现有元音.意思是,给出了一个列表(链接),其中包含每个节点中的字符,我需要以这样的方式隔离其节点,即通过保持原始顺序将具有元音的所有节点移动到链表的末尾.
输出应该像:
original list: w->e->r->s->o->m->a->t
Output needed: w->r->s->m->t->a->e->o
Run Code Online (Sandbox Code Playgroud)
我想在java中实现它.请让我知道这样做的最佳方式(比如不使用任何额外的列表).任何建议,帮助将非常感激.
我试图从linkedhashset中检索随机元素.下面是我的代码,但它每次都给我例外.
private static void generateRandomUserId(Set<String> userIdsSet) {
Random rand = new Random(System.currentTimeMillis());
String[] setArray = (String[]) userIdsSet.toArray();
for (int i = 0; i < 10; ++i) {
System.out.println(setArray[rand.nextInt(userIdsSet.size())]);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我得到的例外 -
java.lang.ClassCastException: [Ljava.lang.Object; incompatible with [Ljava.lang.String;
谁可以帮我这个事?还有更好的方法吗?
我有这种字符串格式的今天日期,2014-05-08我需要获取当前日期之前 2 周的日期。
所以我应该取回的数据是 - 2014-04-24。
String currentDate= dateFormat.format(date); //2014-05-08
String dateBefore2Weeks = currentDate- 2 week;
Run Code Online (Sandbox Code Playgroud)
但我不确定如何在 Java 中提取当前日期前两周的日期?
我是Unix Shell Scripting世界的新手.我想从unix shell脚本运行一个简单的sql查询,并将结果输出到.txt文件中,然后将该.txt文件作为附件发送到电子邮件中.
SQL查询并将输出传递给txt文件:
SELECT count(*) from pds_table > a.txt;
Run Code Online (Sandbox Code Playgroud)
如何从shell脚本执行此操作并将输出发送到txt文件,然后将该txt文件作为电子邮件中的附件发送.
目前我正在使用LinkedList添加所有Command信息.如何使下面的List<Command>线程安全?我应该在这里使用其他选项而不是LinkedList吗?
private static List<Command> commands;
Command command = new Command();
command.setName(commandName);
command.setExecutionPercentage(Double.parseDouble(percentage));
command.setAttributeIDGet(attributeIDGet);
command.setAttributeIDSet(attributeIDSet);
command.setDataUsageCriteria(dataCriteria);
command.setUserLoggingCriteria(userLoggingCriteria);
command.setSleepTime(sleepTimeOfCommand);
Run Code Online (Sandbox Code Playgroud)
我command正在通过从文本文件中读取并将其放入LinkedList of command如下所示的内容中添加以上所有内容.所以如果我有,three command那么我需要将所有这些添加three command到一些LinkedList我正在做的事情中.
commands.add(command);
Run Code Online (Sandbox Code Playgroud)
如果我做下面的事情怎么办? -
Collections.synchronizedList(commands.add(command));
Run Code Online (Sandbox Code Playgroud)
或者我需要做这样的事情 -
commands = Collections.synchronizedList(new LinkedList<Command>());
Run Code Online (Sandbox Code Playgroud)
更新: -
根据你的建议,如果我正在使用 -
private static Queue<Command> commands;
commands = new ConcurrentLinkedQueue<Command>(); // Using linked list to ensure iteration order
Command command = new Command();
command.setName(commandName);
command.setExecutionPercentage(Double.parseDouble(percentage));
command.setAttributeIDGet(attributeIDGet);
command.setAttributeIDSet(attributeIDSet);
command.setDataUsageCriteria(dataCriteria); …Run Code Online (Sandbox Code Playgroud) 以下是其他人写的课程.
我面临的问题是当它进入parse method时null as the rawString,它正在投掷NumberFormatException.
所以我想要做的是,我应该捕获NumberFormatException和set the value itself as null.所以我的方式是对的?
public class ByteAttr {
@JExType(sequence = 1)
private Byte value;
public static ByteAttr parse(String rawString) {
ByteAttr attr = new ByteAttr();
try {
attr.setValue(Byte.valueOf(rawString));
} catch (NumberFormatException nfEx) {
attr.setValue(null);
}
return attr;
}
public Byte getValue() {
return this.value;
}
public void setValue(Byte value) {
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在运行一个程序,它将针对某个 url 生成一些负载,并使用 RestTemplate 进一步使用相同的 URL。
我点击的网址将返回一个简单的字符串Hello World作为响应。
下面的程序将根据 url 生成负载。
public class ShellbareboneLnP {
public static void main(String[] args) {
try {
// create thread pool with given size
ExecutorService service = Executors.newFixedThreadPool(threads);
// queue some tasks
long startTime = System.currentTimeMillis();
long endTime = startTime + (durationOfRun * 60 * 1000);
for (int i = 0; i < threads; i++) {
service.submit(new ShellBareboneTask(endTime));
}
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {
LOG.warn("Threw a Interrupted Exception in" …Run Code Online (Sandbox Code Playgroud) 我试图使用反射在我的一个类中调用一个私有方法,它也接受一个Map参数.
下面是我应该调用的方法,下面的方法是ReflectionTest:
private static Map<String, String> storageSort(final List<Map<String, String>> employeeList) {
}
Run Code Online (Sandbox Code Playgroud)
我这样调用上面的方法:
ReflectionTest io = new ReflectionTest();
Method m = ReflectionTest.class.getDeclaredMethod("storageSort", Map.class);
m.setAccessible(true);
Object o = m.invoke(io, sortList);
Run Code Online (Sandbox Code Playgroud)
但以下是我每次都会得到的例外情况:
java.lang.NoSuchMethodException:com.reflection.test.ReflectionTest.storageSort(java.util.Map)
我不确定我在这里做错了什么?
我正在开发一个项目,我需要使用Python执行shell脚本.到目前为止一切都很好看.
下面是我的Python脚本,它将执行一个简单的hello world shell脚本.
MAX_TRIES = 2
jsonStr = '{"script":"#!/bin/bash \\n echoo Hello world 1 "}'
j = json.loads(jsonStr)
shell_script = j['script']
steps = ['step1', 'step2', 'step3']
for step in steps:
print "start"
print step
for i in xrange(MAX_TRIES):
proc = subprocess.Popen(shell_script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
if stderr:
print "Shell script gave some error..."
sleep(0.05) # delay for 50 ms
else:
print "end" # Shell script ran fine.
break
Run Code Online (Sandbox Code Playgroud)
在我上面的脚本中,如果上面的shell脚本由于某种原因而失败并且工作正常,我会重试两次.
现在我的问题是,在上面的脚本中,我有一个错误的shell脚本,它将失败.我有一个for循环,它将steps逐个迭代列表并执行shell脚本.
目前,每个步骤都会打印出来,这不是我想要的 -
start
step1 …Run Code Online (Sandbox Code Playgroud) 我正在使用Postgresql数据库.我需要使用Postgresql数据库获取当前日期前两周的日期.
select date(now() - interval '2 week') from test_base
Run Code Online (Sandbox Code Playgroud)
如果今天的日期是2014-05-08以上sql应该给我2014-04-24?
但不知何故上面的查询根本不起作用?
String s = 000000001;
String e = 009999999;
Run Code Online (Sandbox Code Playgroud)
将String转换000000001为Integer 000000001.
我尝试使用Integer.parseInt执行此操作
int n = Integer.parseInt(s);
Run Code Online (Sandbox Code Playgroud)
我得到n = 1,但我希望n应该有000000001
for (int ind = Integer.valueOf(s); ind < Integer.valueOf(e); ind++) {
String pp = "ggg" + ind; // I want pp should be like this- ggg000000001 and it keep on increasing like ggg000000002, then ggg000000003 and etc etc.
}
Run Code Online (Sandbox Code Playgroud) java ×9
date ×2
sql ×2
bash ×1
hive ×1
linked-list ×1
map ×1
nested-loops ×1
ora-00936 ×1
oracle ×1
postgresql ×1
python ×1
reflection ×1
resttemplate ×1
shell ×1
unix ×1