title: java sql random row print
body: <p>i try to print random row but i could not   , how can i print random row? </p>
  
  <p>-data base name test
   -table name user_data</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  public class sqlconnect {
  public static void main(String args[]) {
  try {
  
  Class.forName("com.mysql.jdbc.Driver");
  Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root",""); 
  Statement stmt = con.createStatement();
  ResultSet rs=stmt.executeQuery("select * from user_data ORDER BY RANDOM() OFFSET 0 ROWS FETCH NEXT 1 ROW ONLY");
  
  while(rs.next())
  
  System.out.println(rs.getString(1)); 
  con.close();
  } 
  catch (Exception e){ System.out.println(e);} 
  }
  }
  </code></pre>
  
  <p>i try this code this is the error message </p>
  
  <pre><code>com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET 0 ROWS FETCH NEXT 1 ROW ONLY' at line 1
  </code></pre>