SQL 入门学习记录—06-between语法+getdate()自带函数

1.
select * from [dbo].[gm_pstructure]
where Id between ‘WH-AQW-05-1-1203’ and ‘WH-AQW-05-1-1440’

and前面是开头,后面是结尾,查找出来的数据是WH-AQW-05-1-1203 和WH-AQW-05-1-1440之间的数据
在这里插入图片描述

上面我是想查找某一段的数据,相反,现在我想要排除某一段数据,比如现在我想排除WH-AQW-05-1-1203——WH-AQW-05-1-1440之间的数据。
就是在between前面加一个not
select * from [dbo].[gm_pstructure]
where Id not between ‘WH-AQW-05-1-1203’ and ‘WH-AQW-05-1-1440’
在这里插入图片描述
库里一共43400行,现在4339

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用BasicDataSource类创建数据源对象和查询数据的Java代码示例: ```java import java.sql.*; import org.apache.commons.dbcp2.BasicDataSource; public class DBCPUtils { private static final String URL = "jdbc:mysql://localhost:3306/test"; private static final String USERNAME = "root"; private static final String PASSWORD = "password"; private static BasicDataSource dataSource = null; static { dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(URL); dataSource.setUsername(USERNAME); dataSource.setPassword(PASSWORD); dataSource.setInitialSize(5); dataSource.setMaxTotal(10); } public static QueryState queryUserById(int userId) { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; QueryState state = null; try { conn = dataSource.getConnection(); String sql = "SELECT * FROM users WHERE id = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, userId); rs = stmt.executeQuery(); if (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); String password = rs.getString("password"); String email = rs.getString("email"); Date birthday = rs.getDate("birthday"); state = new QueryState(id, name, password, email, birthday); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } return state; } public static void main(String[] args) { QueryState state = queryUserById(1); if (state != null) { System.out.println(state.toString()); } else { System.out.println("No user found."); } } } class QueryState { private int id; private String name; private String password; private String email; private Date birthday; public QueryState(int id, String name, String password, String email, Date birthday) { this.id = id; this.name = name; this.password = password; this.email = email; this.birthday = birthday; } public int getId() { return id; } public String getName() { return name; } public String getPassword() { return password; } public String getEmail() { return email; } public Date getBirthday() { return birthday; } public String toString() { return "id=" + id + ", name=" + name + ", password=" + password + ", email=" + email + ", birthday=" + birthday.toString(); } } ``` 该示例中,我们使用了Apache Commons DBCP数据库连接池库的BasicDataSource类创建了一个数据源对象,然后在queryUserById方法中使用该数据源对象获取数据库连接,执行SQL查询语句,并返回查询结果封装成的QueryState对象。最后在main方法中调用该方法进行查询,并输出查询结果。 需要注意的是,我们在代码中硬编码了数据库连接信息,实际应用中应该将其配置在properties文件中等更安全的方式进行管理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值