JFinal SQL in 查询排序

SQL in 查询会默认把顺序打乱,在JFinal中,可以用case when then end来解决。

代码模板如下:

    select * from table where id in(
	  #for(x:cond)
		#(for.index == 0 ? "" : ",") #para(x)
	    #end
	)
	order by case id
	#for(x:cond)
	     when #para(x) then #(for.index)
	#end
	     end

  

转载于:https://www.cnblogs.com/sxf2017/p/9002732.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你需要执行一个 SQL 查询,是吗?请问你使用的是哪个数据库?如果你使用的是 Java 编程语言,可以使用 JDBC API 来连接数据库并执行查询。以下是一个简单的示例代码,可以查询一个名为“employees”的表中的所有记录: ```java import java.sql.*; public class JdbcExample { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/yourdatabase"; static final String USER = "yourusername"; static final String PASS = "yourpassword"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try { Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt = conn.createStatement(); String sql = "SELECT * FROM employees"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ int id = rs.getInt("id"); String name = rs.getString("name"); int age = rs.getInt("age"); String address = rs.getString("address"); float salary = rs.getFloat("salary"); System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age + ", Address: " + address + ", Salary: " + salary); } rs.close(); stmt.close(); conn.close(); } catch(SQLException se) { se.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } finally { try { if(stmt!=null) stmt.close(); } catch(SQLException se2) { } try { if(conn!=null) conn.close(); } catch(SQLException se) { se.printStackTrace(); } } } } ``` 在这个示例中,我们使用 MySQL 数据库,并使用 JDBC 驱动程序连接到这个数据库。`JDBC_DRIVER` 必须指定为你实际使用的数据库的驱动程序。`DB_URL` 是数据库的 URL,`USER` 和 `PASS` 是数据库的用户名和密码。在 `main` 方法中,我们执行一个查询,使用 `executeQuery` 方法执行 SQL 语句,然后使用 `ResultSet` 对象遍历结果集并打印每个记录的详细信息。最后,我们关闭了所有连接和语句对象。 请注意,这只是一个简单的示例代码,你需要根据你的实际情况进行修改。另外,你需要下载并安装适当的 JDBC 驱动程序,并在你的项目中添加它们的 JAR 文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值