mysql - Java DAO object SQLexception -
new java , mysql.
am using dao object query table, running via eclipse. mysql edited via workbench. table exists , getting following exceptions:
select movie_name, release_dd, release_mm, release_yyyy, duration, language, director, genre, actor_1, actor_2 movie_details_table movie_name = 'piku' java.sql.sqlexception: before start of result set @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:998) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:937) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:926) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:872) @ com.mysql.jdbc.resultsetimpl.checkrowpos(resultsetimpl.java:787) @ com.mysql.jdbc.resultsetimpl.getstringinternal(resultsetimpl.java:5244) @ com.mysql.jdbc.resultsetimpl.getstring(resultsetimpl.java:5167) @ com.mysql.jdbc.resultsetimpl.getstring(resultsetimpl.java:5206) @ com.library.model.moviedao.getmoviedetails(moviedao.java:41) @ com.library.model.moviedettest.main(moviedettest.java:18)
moviedao class:
package com.library.model; import java.util.*; import java.sql.*; import java.io.*; import com.library.model.beans.*; public class moviedao { private static final string db_url = "jdbc:mysql://localhost/planner"; // database credentials private static final string user = "sudipto"; private static final string pass = "sudi85"; public moviedetails getmoviedetails(string inputmov) throws sqlexception { moviedetails moviedetails = new moviedetails(); try { //open connection connection conn = drivermanager.getconnection (db_url,user,pass); //create , execute query string querystring = "select movie_name, release_dd, release_mm, release_yyyy, duration, language, director, genre, actor_1, actor_2 movie_details_table movie_name = '" + inputmov + "'"; system.out.println(querystring); preparedstatement statement = conn.preparestatement (querystring); resultset rsmoviedetails = statement.executequery(); moviedetails.setmoviename(rsmoviedetails.getstring ("movie_name")); moviedetails.setreleasedate (rsmoviedetails.getint ("release_dd"), rsmoviedetails.getint ("release_mm"), rsmoviedetails.getint ("release_yyyy")); moviedetails.setduration(rsmoviedetails.getint ("duration")); moviedetails.setlanguage(rsmoviedetails.getstring ("language")); moviedetails.setdirector(rsmoviedetails.getstring ("director")); moviedetails.setgenre(rsmoviedetails.getstring ("genre")); moviedetails.setactor1(rsmoviedetails.getstring ("actor_1")); moviedetails.setactor2(rsmoviedetails.getstring ("actor_2")); } catch (sqlexception e) { e.printstacktrace(); } return moviedetails; } }
have following error log in mysql workbench:
2015-05-31t15:04:36, 27, note, aborted connection 27 db: 'planner' user: 'sudipto' host: 'localhost' (got error reading communication packets)
can please suggest how , need fix?
use rsmoviedetails.next() retrive details. rs.next() used in https://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html.
rs.next() shifts cursor next row of result set database , returns true if there row, otherwise returns false. if row present u should retrieve data
Comments
Post a Comment