Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy I didn't get results when adding Where clause to my query?
    text
    copied!<p>I'm using Mysql JDBC driver.. but I have some problem.. </p> <p>the problem is when I use <code>SELECT</code> Query in java source code.</p> <p>When I use this query: </p> <pre><code>select * from [name of table] </code></pre> <p>I've gotten result of query from DB successfully.</p> <p>but when I use this query: </p> <pre><code> select * from student where (substring(stu_name,0,1)&gt;= '가' and substring(stu_name,0,1) &lt; '나') ; </code></pre> <p>I've not gotten result of query from DB..</p> <p>The difference thing is just that using <code>where</code> or not.</p> <p><strong>What's the problem?</strong></p> <p><strong>How can I solve this problem?</strong></p> <p>this is my code below</p> <p>this query isn't working</p> <pre><code>select * from student where (substring(stu_name,0,1)&gt;= '가' and substring(stu_name,0,1) &lt; '나') ; </code></pre> <p>this query is working very well</p> <pre><code>select * from student; </code></pre> <p>The difference thing is just only query information .. rest of the source code is the same absolutely</p> <hr> <p>I added my java source code public class Center {</p> <pre><code>/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String sql = "select * from student where (substring(stu_name,0,1)&gt;= '가' and substring(stu_name,0,1) &lt; '나') "; String url = "jdbc:mysql://localhost:3306/test"; String driverName = "com.mysql.jdbc.Driver"; String id = "root"; String password = "jsyun0415"; Connection con = null; PreparedStatement prepareState = null; Statement stmt = null; ResultSet rs = null; ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; list_second = new ArrayList&lt;String&gt;(); try { Class.forName(driverName); } catch (ClassNotFoundException e) { System.out.println("Failed to load JDBC driver.."); e.printStackTrace(); return; } try { con = DriverManager.getConnection(url, id, password); stmt = con.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { list.add(rs.getNString("stu_no")); list_second.add(rs.getNString("stu_ename")); } //test = list.get(2); } catch (SQLException sqex) { System.out.println("SQLException: " + sqex.getMessage()); System.out.println("SQLState: " + sqex.getSQLState()); } finally { try { if (stmt != null) stmt.close(); if (con != null) con.close(); if (rs != null) rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload