小编Eri*_*ric的帖子

如何使用Jersey Client API在RESTful调用上添加Headers

这是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)

java rest header jersey request

37
推荐指数
4
解决办法
15万
查看次数

如何在mysql中插入NULL,尤其是INT dataType

我有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)

希望有人可以帮助我.谢谢.

java mysql jdbc

13
推荐指数
2
解决办法
3万
查看次数

如何提高每秒MySQL数据库的InnoDB写入速度

在我的服务器上,将记录插入MySQL DB非常慢.关于服务器状态,每秒InnoDB写入大约20.

我不是专家,只是从大学毕业.我没有太多的经验.我怎样才能提高InnoDB写入的速度?如果不升级我的服务器的硬件,有什么办法可以做到吗?

我的服务器不好,所以我安装了Microsoft Windows Server 2003 R2.硬件信息如下:

  • CPU:Intel Xeon E5649 2.53GHZ
  • 内存:2GB

有任何意见,谢谢.

mysql sql performance

4
推荐指数
2
解决办法
1万
查看次数

Error in Hibernate simple example Beginner level

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示例项目中的详细信息):

  1. 我的Eclipse项目名称:HibernateExa
  2. 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)

java hibernate

3
推荐指数
1
解决办法
3万
查看次数

使用JAVA中的JDBC在单个查询中将多行插入两个表中

我有两个表学生(身份证,姓名,城市),老师(身份证,姓名,工资).插入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,我可以写一个查询来完成它.

java mysql sql jdbc

1
推荐指数
1
解决办法
6426
查看次数

为什么Date会自动添加1个月?

基本上,我希望我的结果是我所期望的打印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个月吗?谢谢.

java calendar date

0
推荐指数
1
解决办法
91
查看次数

如何解决ArrayIndexOutofBoundsException

我拆分为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".

谢谢.

java split

-1
推荐指数
1
解决办法
1320
查看次数

标签 统计

java ×6

mysql ×3

jdbc ×2

sql ×2

calendar ×1

date ×1

header ×1

hibernate ×1

jersey ×1

performance ×1

request ×1

rest ×1

split ×1