jsqlparser

How to add where condition to sql with JSqlParser?

六月ゝ 毕业季﹏ 提交于 2021-02-10 06:32:34
问题 I want to add where condition to sql with JSqlParser, for example: Before: select * from test_table where a=1 group by c After: select * from test_table where a=1 and b=2 group by c However, I cannot find any example codes. 回答1: One solution would be: String sql = "select * from test_table where a=1 group by c"; Select select = (Select) CCJSqlParserUtil.parse(sql); Expression where = CCJSqlParserUtil.parseCondExpression("a=1 and b=2"); ((PlainSelect) select.getSelectBody()).setWhere(where);

How to add where condition to sql with JSqlParser?

浪子不回头ぞ 提交于 2021-02-10 06:32:30
问题 I want to add where condition to sql with JSqlParser, for example: Before: select * from test_table where a=1 group by c After: select * from test_table where a=1 and b=2 group by c However, I cannot find any example codes. 回答1: One solution would be: String sql = "select * from test_table where a=1 group by c"; Select select = (Select) CCJSqlParserUtil.parse(sql); Expression where = CCJSqlParserUtil.parseCondExpression("a=1 and b=2"); ((PlainSelect) select.getSelectBody()).setWhere(where);

PageHelper分页插件的原理是什么

前提是你 提交于 2021-02-02 04:43:07
作者:祖大俊 原文: https: / /my.oschina.net/zudajun /blog/ 745232 PageHelper是一款好用的开源免费的Mybatis第三方物理分页插件,其实我并不想加上好用两个字,但是为了表扬插件作者开源免费的崇高精神,我毫不犹豫的加上了好用一词作为赞美。 原本以为分页插件,应该是很简单的,然而PageHelper比我想象的要复杂许多,它做的很强大,也很彻底,强大到使用者可能并不需要这么多功能,彻底到一参可以两用。但是,我认为,作为分页插件,完成物理分页任务是根本,其它的很多智能并不是必要的,保持它够傻够憨,专业术语叫stupid,简单就是美。 我们将简单介绍PageHelper的基本使用和配置参数的含义,重点分析PageHelper作为Mybatis分页插件的实现原理。 1. PageHelper的maven依赖及插件配置 < dependency > < groupId > com.github.pagehelper </ groupId > < artifactId > pagehelper </ artifactId > < version > 4.1.6 </ version > </ dependency > PageHelper除了本身的jar包外,它还依赖了一个叫jsqlparser的jar包,使用时

How to add new condition with JSqlParser?

非 Y 不嫁゛ 提交于 2020-06-28 04:43:17
问题 I want to add new condition to my sql. For example If query is; SELECT EMP_ID, FIRST_NAME FROM EMPLOYEES; I can add new where cause with this codes; @Override protected void setLimit(final PlainSelect ps,final long rowLimit) { Expression where = ps.getWhere(); if(where == null) { try { where = CCJSqlParserUtil.parseCondExpression("ROWNUM < " + (rowLimit+1) ); } catch (JSQLParserException e) { e.printStackTrace(); } } ps.setWhere(where); } This codes changes the query to SELECT EMP_ID, FIRST

MySQL建表语句转PostgreSQL建表语句全纪录

回眸只為那壹抹淺笑 提交于 2020-02-29 12:06:18
个人习惯用MySQL workbench EER数据建模,然后生成SQL语句到数据库中执行,这样表之间的关系比较直观。 像下面这样: 画图 正向工程,生成DDL语句: 忽略生成外键,以及外键索引啥的: 生成的DDL语句: 到数据库执行。 踩坑了 最近团队微调,我被调整到另一个小团队。前两天接了个新需求,于是我依然使用MySQL workbench EER建模,结果好不容易建模完成了,却被告知这个项目用的数据库是PostgreSQL! 于是就面临如下几种选择: 重新找个支持导出PostgreSQL DDL语句的建模软件,再弄一遍。据我所知,macOS平台里没啥好的数据建模软件… PowerDesigner用不了(除非装虚拟机,或者Wine); Navicat太难用了(居然有人说Navicat是最好的数据库客户端,我只能给一个大写的服,在我看来,这货连IDEA自带数据库管理都比不上……这观点可能有点偏激,但现状是我做个查询,Navicat把查询按钮藏得很深); IDEA宣布会开发类似功能,但一直没有动静; 开源的PDMan,体验挺不错,但也得连个数据库控制版本。 依然用MySQL workbench导出DDL,然后自己将MySQL DDL转换成PostgreSQL DDL。 我选择了自己转换SQL语句。 开源的DDL转换工具 既然要转换SQL语句,我心想,业界肯定有相关的工具啊

MyBatis-PageHelper分页工具类

让人想犯罪 __ 提交于 2020-02-27 14:24:27
PageHelper 是 MyBatis 中非常方便的第三方分页插件 官方文档: https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md 我们可以对照官方文档的说明,快速的使用插件 PageHelper 的使用步骤 导入相关包 pagehelper-x.x.x.jar 和 jsqlparser-0.9.5.jar 在 MyBatis 全局配置文件中配置分页插件 <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin> </plugins> PageHelper分页工具类 /** * 首页 上一页 1 2 3 4 5 下一页 末页 * */ public class PageUtil { public static String getPageInfo(PageInfo<Emp> pageInfo, HttpServletRequest request) { String path = request.getContextPath() + "/"; StringBuilder builder = new StringBuilder(); //拼接首页 builder.append("<a

【SSM_09】Mybatis-多表操作、插件

独自空忆成欢 提交于 2020-02-27 12:52:58
一、映射文件增强 1. 动态 sql ① if 标签 <select id="find" parameterType="demo" resultType="demo"> select * from test <!-- where 标签中 if 有成立的会再 sql 语句后面自动添加 where --> <where> <!-- if 标签判断,条件成立后会添加标签体内容 and 底层处理 第一个自动去掉 and --> <if test="id != null"> and id = #{id} </if> <if test="name != null"> and name = #{name} </if> <if test="phone != null"> and phone = #{phone} </if> </where> </select> ---------------------------------------------------------------------------------------------------------------- ② forearch 标签 <select id="in" parameterType="demo" resultType="demo"> select * from test <where> <!-- 传入一个容器

Parsing table and column names from SQL/HQL Java

你。 提交于 2019-12-24 08:17:07
问题 I am looking for an open source API in Java to parse an SQL / HQL query so that it gives me the column names and the table names used in it. I tried using JSQLParser which gives me the table names used in the query. But I don't see a support for getting the column names used in the query. Is there any other API which can help me with this? I am aware of General SQL parser but it seems to be a paid one. Here is the code snippet using JSQLParser which gives me the table names in the query:

JSqlParser - Pretty print where clause

我是研究僧i 提交于 2019-12-24 02:25:34
问题 I have started to use JSqlParser, i can parse a Where clause but i don't manage to go further with it. JSqlParser github link Indeed, i have tried to Override visit methods but don't understand how to reach my goal. Let's say i have: (a=1 AND (b=2 OR (c=3 AND d=4))) OR e=2 as input and i would like as output: -> a=1 -> AND --> b=2 --> OR ---> c=3 ---> AND ---> d=4 -> OR -> e=5 My final goal is not a pretty print, but to understand how to know the current depth of the print at a given state.

How to do unit testing of Visitors in Jsqlparser?

徘徊边缘 提交于 2019-12-12 00:49:05
问题 I have implemented the Visitors of JSqlparser to parse SQL queries. The code is working absolutely fine. I am not sure how to do unit testing for those visitors. For example I have the following sql statement: Select a.a1, a.a2 from foo as a To parse it I have implemented StatementVisitor interface and my code goes like this: public class StmntVisitorImpl implements StatementVisitor { @Override public void visit(Select select) { LOG.debug("Begin Select visit : "+select.toString());