package com.powernode.jdbc.utils; import java.sql.*; public class Fake { //模糊查询 public static void main(String[] args) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { //获取连接 connection = DBUtil.getConnection(); String sql = "select * from users where username like ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1,"_l%"); resultSet = preparedStatement.executeQuery(); if(resultSet.next()) { System.out.println(resultSet.getString("email")); System.out.println(resultSet.getString("username")); System.out.println(resultSet.getString("pssword")); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(connection,preparedStatement,resultSet); } } }
package com.powernode.jdbc.utils;
import java.sql.*;
public class Fake
{
//模糊查询
public static void main(String[] args)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try
{
//获取连接
connection = DBUtil.getConnection();
String sql = "select * from users where username like ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,"_l%");
resultSet = preparedStatement.executeQuery();
if(resultSet.next())
{
System.out.println(resultSet.getString("email"));
System.out.println(resultSet.getString("username"));
System.out.println(resultSet.getString("pssword"));
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(connection,preparedStatement,resultSet);
}
}
}
package com.powernode.jdbc.utils; import java.sql.*; public class Fake { //模糊查询 public static void main(String[] args) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { //获取连接 connection = DBUtil.getConnection(); String sql = "select * from users where username like ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1,"_l%"); resultSet = preparedStatement.executeQuery(); if(resultSet.next()) { System.out.println(resultSet.getString("email")); System.out.println(resultSet.getString("username")); System.out.println(resultSet.getString("pssword")); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(connection,preparedStatement,resultSet); } } }
package com.powernode.jdbc.utils;
import java.sql.*;
public class Fake
{
//模糊查询
public static void main(String[] args)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try
{
//获取连接
connection = DBUtil.getConnection();
String sql = "select * from users where username like ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,"_l%");
resultSet = preparedStatement.executeQuery();
if(resultSet.next())
{
System.out.println(resultSet.getString("email"));
System.out.println(resultSet.getString("username"));
System.out.println(resultSet.getString("pssword"));
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(connection,preparedStatement,resultSet);
}
}
}