java - Running javacode with MySQL connectivity does not fetch proper results -


iam new java , wrote below code fetch mysql workbench table using java code:

           package filereader;            import java.sql.*;                 public class dbconnection {               public static void main(string[] args)      {     connection con = null;     statement st = null;      try     {        class.forname("com.mysql.jdbc.driver");      con  = drivermanager.getconnection("jdbc:mysql://localhost:3306/world","root","password");      st = con.createstatement();     string sql = "select * city id = 1;";     resultset rs = st.executequery(sql);     while(rs.next())     {         int id = rs.getint("id");         string name = rs.getstring("name");         string countrycode = rs.getstring("countrycode");         string district = rs.getstring("district");         int population = rs.getint("population");                    system.out.println(id);         system.out.println(name);         system.out.println(countrycode);         system.out.println(district);         system.out.println(population);              }     rs.close();     st.close();     con.close();     }catch(exception e) {     e.printstacktrace();         }finally {     try{          if(st!=null)             st.close();       }catch(sqlexception se2){       }       try{          if(con!=null)             con.close();       }catch(sqlexception se){          se.printstacktrace();       }    }    system.out.println("goodbye!"); } 

}

on running it, connection made results not fetched properly. 1st row fetched first column missing.

logs/statements seen:

 sat mar 28 21:34:36 ist 2015 trace: <--  buffer.java:292         com.mysql.jdbc.buffer.readint(..) returning 2  sat mar 28 21:34:36 ist 2015 trace: <--  mysqlio.java:2247 com.mysql.jdbc.mysqlio.readserverstatusforresultsets(..) returning null  sat mar 28 21:34:36 ist 2015 trace: --> connection.java:5895 com.mysql.jdbc.connection.versionmeetsminimum(5, 0, 2)  sat mar 28 21:34:36 ist 2015 trace: --> connection.java:1903 com.mysql.jdbc.connection.checkclosed() 

....and on

what doing wrong here?


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -