LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2004, 12:41 PM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
recordset in java, db - mysql


i have 2 tables in a database patients and reports

depending on the certain conditions i either update both tables (patients followed by reports) or just reports

this is my code for updation of patients followed by reports

Code:
SQLStmt ="insert into patients (ssn, name, dob) "
			+ "values('"
			+ data[1]
			+ "','"
			+ data[2]
			+ "','"
			+ data[3]
			+ "');";
stmt.execute(SQLStmt);

// retrive patient_id
SQLStmt ="select patient_id from patients where ssn = '"
			+ data[1]
			+ "';";
	
rs1 = stmt.executeQuery(SQLStmt);

// insert record in reports

SQLStmt = " insert into reports (patient_id, report_date) "
			+ "values('"
			+ rs1.getString("patient_id")           // line 82 
			+ "','"
			+ data[0]
			+ "');";	
stmt.execute(SQLStmt);


when i am trying to update both the tables ... an update on 'reports' can be done only after getting the patient_id (primary key, auto generated)from 'patients' i get the following error

java.sql.SQLException: Before start of result set
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:3624)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1763)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1827)
at uds.util.Update.updateDb(Update.java:82)
at call.main(call.java:33)

wht could be the problem

thanks in advance
 
Old 06-18-2004, 03:19 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You will need a seprate connection to the database for the select.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql and mysql java connector, connection refused arubin Slackware 3 03-29-2008 01:41 AM
Help me in connecting Java and Mysql deepanvenkatesh Programming 4 10-29-2005 12:34 PM
Write the Database RecordSet class nelnel Programming 2 09-14-2005 08:53 PM
getting an oracle recordset with netbeans saavik Programming 1 03-30-2005 05:18 AM
java and mysql linux_ub Programming 5 06-24-2004 10:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration