Java - PreparedStatement Like 查詢寫法

摘要:Java - PreparedStatement Like 查詢寫法

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn =  DriverManager.getConnection(conn_string);

String sql = " select * from table where col_name like ? "

PreparedStatement pstmt = conn.prepareStatement(Sql);

pstmt.setString(1,"%" + col_value + "%");

Result rs = pstmt.executeQuery();