0%

同表,根据查找出来的主键id,进行删除,会报错。

比如:

1
2
3
DELETE FROM t_user WHERE id IN(
SELECT id FROM t_user WHERE name = "Hello"
)

Error Code: 1093. You can't specify target table 't_user' for update in FROM clause

解决方案:

把查出来的结果生成一个临时表。

1
2
3
4
DELETE FROM t_user WHERE id IN(
SELECT tmp.id FROM
(SELECT id FROM t_user WHERE name = "Hello") tmp
)

但这时有可能还会报个错,提示这是不安全的操作方法。

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. To disable safe mode, toggle the option in Preference -> SQL Editor and reconnect.

这时可以通过以下语句关掉安全阀。

1
SET SQL_SAFE_UPDATES = 0;

再次执行删除命令就可以成功执行了。

打印日志时,一个对象比较大的时候,json字符串比较长,阅读性不强。

这时可以通过一些工具,把json格式化,美化一下,能更方便的阅读。

jackson方式

1
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);

Gson方式

1
2
Gson gson = new GsonBuilder().setPrettyPrinting().create();
gson.toJson(obj);

我们在使用官方提供的GlusterFS Java API,可能会遇到很多坑。

1
2
3
4
5
6
7
8
9
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no libgfapi-jni64-1.0.5-SNAPSHOT in java.library.path, no libgfapi-jni-1.0.5-SNAPSHOT in java.library.path, no libgfapi-jni in java.library.path, /tmp/liblibgfapi-jni-64-1-5094135110056410243.0: libgfapi.so.0: cannot open shared object file: No such file or directory]
at org.fusesource.hawtjni.runtime.Library.doLoad(Library.java:182)
at org.fusesource.hawtjni.runtime.Library.load(Library.java:140)
at com.peircean.libgfapi_jni.internal.GLFS.<clinit>(GLFS.java:52)
at com.peircean.glusterfs.GlusterFileSystemProvider.glfsNew(GlusterFileSystemProvider.java:70)
at com.peircean.glusterfs.GlusterFileSystemProvider.newFileSystem(GlusterFileSystemProvider.java:43)
at com.peircean.glusterfs.GlusterFileSystemProvider.getPath(GlusterFileSystemProvider.java:111)
at java.nio.file.Paths.get(Paths.java:143)
at com.peircean.glusterfs.example.Example.main(Example.java:43)