SQLException in JavaFX Constructor [duplicate]












0
















This question already has an answer here:




  • ResultSet exception - before start of result set

    6 answers




I have created a scene that shows data which gets fetched from Database. This data is assigned to variables in the Constructor called 'Details()'.
Constructor takes an argument 'rollNo'. I am supposed to assign the data to variables in the constructor from Database querying on the basis of 'rollNo' .



I don't understand why this is giving SQLException .....



Please help



public class Details extends Application {

static Connection con = ConnectionUtil.getDataBaseConnection();
String query = "SELECT * from student WHERE rno = ?";

ResultSet rs;

PreparedStatement pst;

public static String name;
public static String course;
public static String roll;
public static String address;
public static String phone;
public static String yoj;
public static String parent;
public static String parPhone;
public static String attendance;


Details(String rollNo) {
System.out.println("Details rollNo = " + rollNo);
try {
roll = rollNo;

pst = con.prepareStatement(query);
pst.setString(1, rollNo);

rs = pst.executeQuery();

name = rs.getString("name");
course = rs.getString("course");
roll = rs.getString("rno");
address = rs.getString("address");
phone = rs.getString("contact");
yoj = rs.getString("yoj");
parent = rs.getString("prntName");
parPhone = rs.getString("prntCntct");
attendance = rs.getString("classesAttended");
System.out.println("***" + rs.getString("name") + "***");

} catch (SQLException e) {
e.printStackTrace();
}
}


@Override
public void start(Stage primaryStage) {
try {



Parent root = FXMLLoader.load(getClass().getResource("/FXML/Details.fxml"));
Scene scene = new Scene(root,750,420);
primaryStage.setScene(scene);
primaryStage.setTitle("Attendance AITH");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
launch(args);
}


It gives following output on console:



    Details rollNo = 3
java.sql.SQLException: Before start of result set
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:516)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:944)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:966)
at application.Details.<init>(Details.java:45)
at application.StudentTableUtil$3$1.lambda$0(StudentTableUtil.java:150)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
controller Details.name=null
****************************3***********









share|improve this question















marked as duplicate by fabian javafx
Users with the  javafx badge can single-handedly close javafx questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 10:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Well, in his exception he writes what was wrong. We know where to know after keeping it in secret :)

    – mr mcwolf
    Nov 20 '18 at 7:26











  • Sorry I didn't got you... Can you clarify please...

    – KRISHNA GUPTA
    Nov 20 '18 at 7:34








  • 1





    Please edit your question (by clicking on the edit link below it) and add the full error message of the exception. (edit your question do not post additional information in comments)

    – a_horse_with_no_name
    Nov 20 '18 at 7:40











  • Edited (Added the Output on console)

    – KRISHNA GUPTA
    Nov 20 '18 at 7:48











  • use if(rs.next()) { ... before call rs.getXXX

    – mr mcwolf
    Nov 20 '18 at 7:51
















0
















This question already has an answer here:




  • ResultSet exception - before start of result set

    6 answers




I have created a scene that shows data which gets fetched from Database. This data is assigned to variables in the Constructor called 'Details()'.
Constructor takes an argument 'rollNo'. I am supposed to assign the data to variables in the constructor from Database querying on the basis of 'rollNo' .



I don't understand why this is giving SQLException .....



Please help



public class Details extends Application {

static Connection con = ConnectionUtil.getDataBaseConnection();
String query = "SELECT * from student WHERE rno = ?";

ResultSet rs;

PreparedStatement pst;

public static String name;
public static String course;
public static String roll;
public static String address;
public static String phone;
public static String yoj;
public static String parent;
public static String parPhone;
public static String attendance;


Details(String rollNo) {
System.out.println("Details rollNo = " + rollNo);
try {
roll = rollNo;

pst = con.prepareStatement(query);
pst.setString(1, rollNo);

rs = pst.executeQuery();

name = rs.getString("name");
course = rs.getString("course");
roll = rs.getString("rno");
address = rs.getString("address");
phone = rs.getString("contact");
yoj = rs.getString("yoj");
parent = rs.getString("prntName");
parPhone = rs.getString("prntCntct");
attendance = rs.getString("classesAttended");
System.out.println("***" + rs.getString("name") + "***");

} catch (SQLException e) {
e.printStackTrace();
}
}


@Override
public void start(Stage primaryStage) {
try {



Parent root = FXMLLoader.load(getClass().getResource("/FXML/Details.fxml"));
Scene scene = new Scene(root,750,420);
primaryStage.setScene(scene);
primaryStage.setTitle("Attendance AITH");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
launch(args);
}


It gives following output on console:



    Details rollNo = 3
java.sql.SQLException: Before start of result set
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:516)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:944)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:966)
at application.Details.<init>(Details.java:45)
at application.StudentTableUtil$3$1.lambda$0(StudentTableUtil.java:150)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
controller Details.name=null
****************************3***********









share|improve this question















marked as duplicate by fabian javafx
Users with the  javafx badge can single-handedly close javafx questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 10:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Well, in his exception he writes what was wrong. We know where to know after keeping it in secret :)

    – mr mcwolf
    Nov 20 '18 at 7:26











  • Sorry I didn't got you... Can you clarify please...

    – KRISHNA GUPTA
    Nov 20 '18 at 7:34








  • 1





    Please edit your question (by clicking on the edit link below it) and add the full error message of the exception. (edit your question do not post additional information in comments)

    – a_horse_with_no_name
    Nov 20 '18 at 7:40











  • Edited (Added the Output on console)

    – KRISHNA GUPTA
    Nov 20 '18 at 7:48











  • use if(rs.next()) { ... before call rs.getXXX

    – mr mcwolf
    Nov 20 '18 at 7:51














0












0








0









This question already has an answer here:




  • ResultSet exception - before start of result set

    6 answers




I have created a scene that shows data which gets fetched from Database. This data is assigned to variables in the Constructor called 'Details()'.
Constructor takes an argument 'rollNo'. I am supposed to assign the data to variables in the constructor from Database querying on the basis of 'rollNo' .



I don't understand why this is giving SQLException .....



Please help



public class Details extends Application {

static Connection con = ConnectionUtil.getDataBaseConnection();
String query = "SELECT * from student WHERE rno = ?";

ResultSet rs;

PreparedStatement pst;

public static String name;
public static String course;
public static String roll;
public static String address;
public static String phone;
public static String yoj;
public static String parent;
public static String parPhone;
public static String attendance;


Details(String rollNo) {
System.out.println("Details rollNo = " + rollNo);
try {
roll = rollNo;

pst = con.prepareStatement(query);
pst.setString(1, rollNo);

rs = pst.executeQuery();

name = rs.getString("name");
course = rs.getString("course");
roll = rs.getString("rno");
address = rs.getString("address");
phone = rs.getString("contact");
yoj = rs.getString("yoj");
parent = rs.getString("prntName");
parPhone = rs.getString("prntCntct");
attendance = rs.getString("classesAttended");
System.out.println("***" + rs.getString("name") + "***");

} catch (SQLException e) {
e.printStackTrace();
}
}


@Override
public void start(Stage primaryStage) {
try {



Parent root = FXMLLoader.load(getClass().getResource("/FXML/Details.fxml"));
Scene scene = new Scene(root,750,420);
primaryStage.setScene(scene);
primaryStage.setTitle("Attendance AITH");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
launch(args);
}


It gives following output on console:



    Details rollNo = 3
java.sql.SQLException: Before start of result set
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:516)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:944)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:966)
at application.Details.<init>(Details.java:45)
at application.StudentTableUtil$3$1.lambda$0(StudentTableUtil.java:150)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
controller Details.name=null
****************************3***********









share|improve this question

















This question already has an answer here:




  • ResultSet exception - before start of result set

    6 answers




I have created a scene that shows data which gets fetched from Database. This data is assigned to variables in the Constructor called 'Details()'.
Constructor takes an argument 'rollNo'. I am supposed to assign the data to variables in the constructor from Database querying on the basis of 'rollNo' .



I don't understand why this is giving SQLException .....



Please help



public class Details extends Application {

static Connection con = ConnectionUtil.getDataBaseConnection();
String query = "SELECT * from student WHERE rno = ?";

ResultSet rs;

PreparedStatement pst;

public static String name;
public static String course;
public static String roll;
public static String address;
public static String phone;
public static String yoj;
public static String parent;
public static String parPhone;
public static String attendance;


Details(String rollNo) {
System.out.println("Details rollNo = " + rollNo);
try {
roll = rollNo;

pst = con.prepareStatement(query);
pst.setString(1, rollNo);

rs = pst.executeQuery();

name = rs.getString("name");
course = rs.getString("course");
roll = rs.getString("rno");
address = rs.getString("address");
phone = rs.getString("contact");
yoj = rs.getString("yoj");
parent = rs.getString("prntName");
parPhone = rs.getString("prntCntct");
attendance = rs.getString("classesAttended");
System.out.println("***" + rs.getString("name") + "***");

} catch (SQLException e) {
e.printStackTrace();
}
}


@Override
public void start(Stage primaryStage) {
try {



Parent root = FXMLLoader.load(getClass().getResource("/FXML/Details.fxml"));
Scene scene = new Scene(root,750,420);
primaryStage.setScene(scene);
primaryStage.setTitle("Attendance AITH");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
launch(args);
}


It gives following output on console:



    Details rollNo = 3
java.sql.SQLException: Before start of result set
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:516)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:944)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:966)
at application.Details.<init>(Details.java:45)
at application.StudentTableUtil$3$1.lambda$0(StudentTableUtil.java:150)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
controller Details.name=null
****************************3***********




This question already has an answer here:




  • ResultSet exception - before start of result set

    6 answers








java javafx constructor sqlexception






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 7:48







KRISHNA GUPTA

















asked Nov 20 '18 at 6:44









KRISHNA GUPTAKRISHNA GUPTA

93




93




marked as duplicate by fabian javafx
Users with the  javafx badge can single-handedly close javafx questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 10:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by fabian javafx
Users with the  javafx badge can single-handedly close javafx questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 10:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Well, in his exception he writes what was wrong. We know where to know after keeping it in secret :)

    – mr mcwolf
    Nov 20 '18 at 7:26











  • Sorry I didn't got you... Can you clarify please...

    – KRISHNA GUPTA
    Nov 20 '18 at 7:34








  • 1





    Please edit your question (by clicking on the edit link below it) and add the full error message of the exception. (edit your question do not post additional information in comments)

    – a_horse_with_no_name
    Nov 20 '18 at 7:40











  • Edited (Added the Output on console)

    – KRISHNA GUPTA
    Nov 20 '18 at 7:48











  • use if(rs.next()) { ... before call rs.getXXX

    – mr mcwolf
    Nov 20 '18 at 7:51



















  • Well, in his exception he writes what was wrong. We know where to know after keeping it in secret :)

    – mr mcwolf
    Nov 20 '18 at 7:26











  • Sorry I didn't got you... Can you clarify please...

    – KRISHNA GUPTA
    Nov 20 '18 at 7:34








  • 1





    Please edit your question (by clicking on the edit link below it) and add the full error message of the exception. (edit your question do not post additional information in comments)

    – a_horse_with_no_name
    Nov 20 '18 at 7:40











  • Edited (Added the Output on console)

    – KRISHNA GUPTA
    Nov 20 '18 at 7:48











  • use if(rs.next()) { ... before call rs.getXXX

    – mr mcwolf
    Nov 20 '18 at 7:51

















Well, in his exception he writes what was wrong. We know where to know after keeping it in secret :)

– mr mcwolf
Nov 20 '18 at 7:26





Well, in his exception he writes what was wrong. We know where to know after keeping it in secret :)

– mr mcwolf
Nov 20 '18 at 7:26













Sorry I didn't got you... Can you clarify please...

– KRISHNA GUPTA
Nov 20 '18 at 7:34







Sorry I didn't got you... Can you clarify please...

– KRISHNA GUPTA
Nov 20 '18 at 7:34






1




1





Please edit your question (by clicking on the edit link below it) and add the full error message of the exception. (edit your question do not post additional information in comments)

– a_horse_with_no_name
Nov 20 '18 at 7:40





Please edit your question (by clicking on the edit link below it) and add the full error message of the exception. (edit your question do not post additional information in comments)

– a_horse_with_no_name
Nov 20 '18 at 7:40













Edited (Added the Output on console)

– KRISHNA GUPTA
Nov 20 '18 at 7:48





Edited (Added the Output on console)

– KRISHNA GUPTA
Nov 20 '18 at 7:48













use if(rs.next()) { ... before call rs.getXXX

– mr mcwolf
Nov 20 '18 at 7:51





use if(rs.next()) { ... before call rs.getXXX

– mr mcwolf
Nov 20 '18 at 7:51












1 Answer
1






active

oldest

votes


















1














If you don't understand why an exception is raised, then look at what the system is telling you about it (hint : e. getMessage() ).



That said, looking at your code, you are accessing the data without first checking that there is any data in the first place, so that might be the reason.






share|improve this answer
























  • But it is giving SQLException

    – KRISHNA GUPTA
    Nov 20 '18 at 7:51











  • Yes you are right it wasn't working because I was fetching the data without checking.

    – KRISHNA GUPTA
    Nov 20 '18 at 7:57


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you don't understand why an exception is raised, then look at what the system is telling you about it (hint : e. getMessage() ).



That said, looking at your code, you are accessing the data without first checking that there is any data in the first place, so that might be the reason.






share|improve this answer
























  • But it is giving SQLException

    – KRISHNA GUPTA
    Nov 20 '18 at 7:51











  • Yes you are right it wasn't working because I was fetching the data without checking.

    – KRISHNA GUPTA
    Nov 20 '18 at 7:57
















1














If you don't understand why an exception is raised, then look at what the system is telling you about it (hint : e. getMessage() ).



That said, looking at your code, you are accessing the data without first checking that there is any data in the first place, so that might be the reason.






share|improve this answer
























  • But it is giving SQLException

    – KRISHNA GUPTA
    Nov 20 '18 at 7:51











  • Yes you are right it wasn't working because I was fetching the data without checking.

    – KRISHNA GUPTA
    Nov 20 '18 at 7:57














1












1








1







If you don't understand why an exception is raised, then look at what the system is telling you about it (hint : e. getMessage() ).



That said, looking at your code, you are accessing the data without first checking that there is any data in the first place, so that might be the reason.






share|improve this answer













If you don't understand why an exception is raised, then look at what the system is telling you about it (hint : e. getMessage() ).



That said, looking at your code, you are accessing the data without first checking that there is any data in the first place, so that might be the reason.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 7:47









Erwin SmoutErwin Smout

15k42148




15k42148













  • But it is giving SQLException

    – KRISHNA GUPTA
    Nov 20 '18 at 7:51











  • Yes you are right it wasn't working because I was fetching the data without checking.

    – KRISHNA GUPTA
    Nov 20 '18 at 7:57



















  • But it is giving SQLException

    – KRISHNA GUPTA
    Nov 20 '18 at 7:51











  • Yes you are right it wasn't working because I was fetching the data without checking.

    – KRISHNA GUPTA
    Nov 20 '18 at 7:57

















But it is giving SQLException

– KRISHNA GUPTA
Nov 20 '18 at 7:51





But it is giving SQLException

– KRISHNA GUPTA
Nov 20 '18 at 7:51













Yes you are right it wasn't working because I was fetching the data without checking.

– KRISHNA GUPTA
Nov 20 '18 at 7:57





Yes you are right it wasn't working because I was fetching the data without checking.

– KRISHNA GUPTA
Nov 20 '18 at 7:57





Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents