这是RESTful调用的格式:
HEADERS:
Content-Type: application/json;charset=UTF-8
Authorization: Bearer Rc7JE8P7XUgSCPogjhdsVLMfITqQQrjg
REQUEST:
GET https://api.example.com/1/realTime?json={"selection":{"includeAlerts":"true","selectionType":"registered","selectionMatch":"","isTheEvent":"true","includeRuntime":"true"}}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
try
{
Client client = Client.create();
WebResource webResource =
client.resource("https://api.example.com/1/realTime?json=
{"selection":{"includeAlerts":"true","selectionType":"registered","selectionMatch":"","isTheEvent":"true","includeRuntime":"true"}}");
//add header:Content-Type: application/json;charset=UTF-8
webResource.setProperty("Content-Type", "application/json;charset=UTF-8");
//add header: Authorization Bearer Rc7JE8P7XUgSCPogsdfdLMfITqQQrjg
value = "Bearer " + value;
webResource.setProperty("Authorization", value);
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("json", js);
//Get response from RESTful Server
jsonStr = webResource.get(String.class);
System.out.println("Testing:");
System.out.println(jsonStr);
}
catch (Exception e)
{
System.out.println (e.getMessage());
e.printStackTrace();
System.exit(0);
}
Run Code Online (Sandbox Code Playgroud)
但它返回错误
com.sun.jersey.api.client.UniformInterfaceException: GET https://api.example.com/1/realTime? returned a response status of 500
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:607) …Run Code Online (Sandbox Code Playgroud) 我有80000个需要插入数据库的重新编码,特别是在表中:temp(ts,temp)temp是INT.
问题是差不多有20000个重新编码为空,所以我想知道当dataType为INT时如何在DB中插入NULL.
我试过这个:
String val = null;
//insert(ts, val) into temp
String sql = "INSERT INTO temp" + "(val)" + " VALUES" + "('" + val + "')";
Statement st = (Statement) conn.createStatement();
count = st.executeUpdate(sql);
Run Code Online (Sandbox Code Playgroud)
不幸的是插入是失败的.打印出异常消息:
Incorrect integer value: 'null' for column 'val' at row 1"
Run Code Online (Sandbox Code Playgroud)
希望有人可以帮助我.谢谢.
在我的服务器上,将记录插入MySQL DB非常慢.关于服务器状态,每秒InnoDB写入大约20.
我不是专家,只是从大学毕业.我没有太多的经验.我怎样才能提高InnoDB写入的速度?如果不升级我的服务器的硬件,有什么办法可以做到吗?
我的服务器不好,所以我安装了Microsoft Windows Server 2003 R2.硬件信息如下:
有任何意见,谢谢.
In order to learn hibernate, I write two examples for practising. However, both of them have same error as following:
Failed to create sessionFactory object.java.lang.NoClassDefFoundError: javax/transaction/SystemException Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2248) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214) at org.hibernate.cfg.Configuration.(Configuration.java:184) at com.example.ManageEmployee.main(ManageEmployee.java:17)
基本上,我首先编写POJO,并使用eclipse生成hbm.xml.之后,我编写了管理数据库的主要功能.我试了两次,但遇到了同样的问题.
有人可以给我建议解决这个问题吗?在此之前,使用JDBC构建项目,但这太复杂了.所以我需要学习hibernate.谢谢.
补充(此hibernate示例项目中的详细信息):
hibernate.cfg.xml:
<session-factory>
<!-- hibernate dialect -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">hibernateTest</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatetest;</property>
<property name="hibernate.connection.username">hibernater</property>
<property name="hibernate.default_schema">hibernatetest</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Automatic schema creation(begin) -->
<property name="hibernate.hbm2ddl.auto">create</property> …Run Code Online (Sandbox Code Playgroud)我有两个表学生(身份证,姓名,城市),老师(身份证,姓名,工资).插入Mysql DB需要几行.
INSERT INTO student VALUES ('12', 'Tom', 'New York');
INSERT INTO student VALUES ('13', 'Jack', 'New York');
INSERT INTO teacher VALUES ('01', 'Joy', '42000');
INSERT INTO teacher VALUES ('02', 'Ryan', '39000');
Run Code Online (Sandbox Code Playgroud)
连接器是JAVA中的JDBC,我可以写一个查询来完成它.
基本上,我希望我的结果是我所期望的打印2012-10-23.但是,它非常有线.这是我的代码:
SimpleDateFormat ft = new SimpleDateFormat("YYYY-MM-dd");
Calendar cal = Calendar.getInstance();
cal.set(2012, 10, 22);
cal.add(Calendar.DATE, 1);
Date startDate = new Date();
startDate = cal.getTime();
String date = ft.format(startDate).toString();
System.out.println(date);
Run Code Online (Sandbox Code Playgroud)
我想打印2012-10-23,但结果是2012-11-23.
有人能告诉我它为什么会自动添加1个月吗?谢谢.
我拆分为String,但我没有考虑异常.所以错误就出来了.例如,如果字符串是"2012-10-21,20:00:00 ,,"
Here is the codes:
String str = "2012-10-21,20:00:00,,";
String a[] = str.split(",");
String timestamp = a[0] + "T" + a[1];
String temp = a[2];
System.out.println(timestamp);
System.out.println(temp);
Run Code Online (Sandbox Code Playgroud)
这是错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
Run Code Online (Sandbox Code Playgroud)
实际上,[2]是空的,但我不知道如何处理这个问题.因为在我的String数组中,一些重新编码包含temp的值,例如"2012-10-21,20:00:00,90".
谢谢.