Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Mysql Ordering varchar as int
    primarykey
    data
    text
    <p>I'm trying to solve the following problem in java and msql.</p> <p>if I run the following query directly in mysql records sorted correctly. But when the same query is done through java or connector, NOT the records are sorted. It is as if the query is performed by comparing string and not integer.</p> <blockquote> <p>select * from table1 order by cast(col2 as signed) limit 0,10</p> </blockquote> <p>Code example:</p> <pre><code>public ArrayList&lt;Customers_voip_terminations_details&gt; select_Customers_voip_terminations_details_all(int voipID, int fromrow, int torow, String orderby) throws SQLException { String query = ""; if (fromrow == 0 &amp;&amp; torow == 0) { query = "select * from customers_voip_terminations_details where voipid=? order by cast(? as signed)"; this.preparedStatement = conn.prepareStatement(query); this.preparedStatement.setInt(1, voipID); this.preparedStatement.setString(2, orderby); } else { //Tools tool = new Tools(); query = "select * from customers_voip_terminations_details where voipid=? order by cast(? as signed) LIMIT ?, ?"; this.preparedStatement = conn.prepareStatement(query); this.preparedStatement.setInt(1, voipID); this.preparedStatement.setString(2, orderby); this.preparedStatement.setInt(3, fromrow); this.preparedStatement.setInt(4, torow); } this.resultSet = this.preparedStatement.executeQuery(); ArrayList&lt;Customers_voip_terminations_details&gt; result = new ArrayList&lt;Customers_voip_terminations_details&gt;(); while (this.resultSet.next()) { Customers_voip_terminations_details item = new Customers_voip_terminations_details(); item.registerid = this.resultSet.getInt("registerid"); item.date1 = this.resultSet.getInt("date1"); item.date2 = this.resultSet.getInt("date2"); item.voipid = this.resultSet.getInt("voipid"); item.customerid = this.resultSet.getInt("customerid"); item.countryid = this.resultSet.getInt("countryid"); item.uniquesearch = this.resultSet.getString("uniquesearch").trim(); item.networktypeid = this.resultSet.getInt("networktypeid"); item.zone = this.resultSet.getString("zone").trim(); item.whitecli = this.resultSet.getInt("whitecli"); item.whiteroute = this.resultSet.getInt("whiteroute"); item.acd = this.resultSet.getFloat("acd"); item.asr = this.resultSet.getFloat("asr"); item.pdd = this.resultSet.getInt("pdd"); item.billingtime = this.resultSet.getInt("billingtime"); item.rate = this.resultSet.getDouble("rate"); item.status = this.resultSet.getInt("status"); result.add(item); } this.resultSet.close(); this.preparedStatement.close(); return result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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