
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
What comments can be added to this code?
package attendance; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import javafx.collections.FXCollections; | |
import javafx.collections.ObservableList; | |
public class RFIDTagsDB { | |
privateSqliteDB db; | |
privatestaticObservableList<RFID> dbData; | |
publicRFIDTagsDB() throwsClassNotFoundException{ | |
db = new SqliteDB(); | |
dbData = FXCollections.observableArrayList(); | |
} | |
publicObservableList<RFID>getDBData(){ | |
return dbData; | |
} | |
publicvoidreadOne(intid) { | |
System.out.println("READ One"); | |
try { | |
this.db.stmt =this.db.conn.createStatement(); | |
System.out.println(db.stmt); | |
String sql ="SELECT * FROM RFIDTags " | |
+"WHERE id = "+ id +""; | |
System.out.println(sql); | |
ResultSet rs =this.db.stmt.executeQuery(sql); | |
while( rs.next() ) { | |
dbData.add( | |
newRFID( | |
rs.getInt("id"), | |
rs.getString("content"), | |
rs.getString("status") | |
) | |
); | |
} | |
}catch(Exception e) { | |
System.out.println("Read, Error: "+ e.getMessage()); | |
} | |
} | |
publicvoidread() { | |
System.out.println("READ"); | |
try { | |
this.db.stmt =this.db.conn.createStatement(); | |
System.out.println(db.stmt); | |
String sql ="SELECT * FROM RFIDTags"; | |
System.out.println(sql); | |
ResultSet rs =this.db.stmt.executeQuery(sql); | |
System.out.println(rs); | |
while( rs.next() ) { | |
dbData.add( | |
newRFID( | |
rs.getInt("id"), | |
rs.getString("content"), | |
rs.getString("status") | |
) | |
); | |
} | |
}catch(Exception e) { | |
System.out.println("Read, Error: "+ e.getMessage()); | |
} | |
} | |
publicvoidadd(RFIDrfid) throwsSQLException{ | |
try { | |
String sql ="INSERT INTO RFIDTags(content, status) " | |
+"SELECT '"+ rfid.getContent() +"', '"+ rfid.getStatus() +"' " | |
+"WHERE NOT EXISTS(" | |
+"SELECT content " | |
+"FROM RFIDTags " | |
+"WHERE content = '"+ rfid.getContent() +"' " | |
+")"; | |
db.executeQuery(sql); | |
}catch(Exception e) { | |
System.out.println("Add, Error: "+ e.getMessage() ); | |
} | |
} | |
publicvoidmodify(RFIDrfid) { | |
System.out.println(rfid.getId() +" - "+ rfid.getContent() +" - "+ rfid.getStatus() ); | |
try { | |
String sql ="UPDATE RFIDTags " | |
+"SET " | |
+"content = '"+ rfid.getContent() +"', " | |
+"status = '"+ rfid.getStatus() +"' " | |
+"WHERE " | |
+" id = '"+ rfid.getId()+"'"; | |
db.executeQuery(sql); | |
}catch(Exception e) { | |
System.out.println("Modify, Error: "+ e.getMessage()); | |
} | |
} | |
publicvoidremove(RFIDrfid) { | |
try { | |
String sql ="DELETE FROM RFIDTags " | |
+"WHERE id = '"+ rfid.getId() +"'"; | |
db.executeQuery(sql); | |
}catch(Exception e) { | |
System.out.println("Remove, Error: "+ e.getMessage()); | |
} | |
} | |
publicintgetLastInsertedId() throwsSQLException { | |
ResultSet rs = db.stmt.getGeneratedKeys(); | |
if( rs.next() ) { | |
return rs.getInt(1); | |
} | |
return-1; | |
} | |
publicvoidclose() { | |
this.db.closeConnection(); | |
} | |
} |
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Explain this code detail by detail by using comment } catch (ClassNotFoundException ex) { Logger.getLogger(transportation.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(transportation.class.getName()).log(Level.SEVERE, null, ex); } }arrow_forwardGiven a class called Student with the following fields: id (primary key), name, address, credit hours and quality points. Write the code for Java class which is annotated with appropriate keys to use with Room library so that it can generate appropriate code to create a SQLite table.arrow_forwardJava Program ASAP Please pay attention to the screenshot for test case 2 and 3 and please make sure you match the result. Modify this program so it passes the test cases in Hypergrade becauses it says 5 out of 7 passed. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please enter the file name or type QUIT to exit:"); String fileName = scanner.nextLine(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { ArrayList<String> lines = readFile(fileName); if (lines.isEmpty()) { System.out.println("File " + fileName + " is empty."); } else {…arrow_forward
- MyFileWriterTest.java import static org.junit.Assert.assertEquals; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MyFileWriterTest { MyFileWriter myFileWriter1; MyFileWriter myFileWriter2; MyFileWriter myFileWriter3; MyFileWriter myFileWriter4; @BeforeEach void setUp() { this.myFileWriter1 =new MyFileWriter("test1_fw.txt"); // file with multiple words per line this.myFileWriter2 =new MyFileWriter("test2_fw.txt"); // similar to info.txt file this.myFileWriter3 =new MyFileWriter("test3_fw.txt"); // similar to info.txt file but with personal info added this.myFileWriter4 =new MyFileWriter("test4_fw.txt"); // similar to info.txt file but with different info and personal info added } @Test publicvoid testWriteToFile() { ArrayList<String> actualLines = new ArrayList<String>();…arrow_forwardHow do I remove the space at the end of the result? Code: import java.util.Scanner; public class FinalExamAnswers{ public static void main(String [] args) { manipulateString(); //calls function } //your code here public static void manipulateString() { Scanner sc=new Scanner(System.in); //create Scanner instance System.out.println("Enter a sentence"); String sentence=sc.nextLine(); //input a sentence String[] words=sentence.split(" "); //split the sentence at space and store it in array for(int i=0;i<words.length;i++) //i from 0 to last index { if(i%2==0) //if even index words[i]=words[i].toUpperCase(); //converted to upper case else //if odd index words[i]=words[i].toLowerCase(); //converted to lower case } for(int i=words.length-1;i>=0;i--) //i from last index to 0 {…arrow_forwardimport org.firmata4j.IODevice;import org.firmata4j.Pin;import org.firmata4j.firmata.FirmataDevice;import org.firmata4j.ssd1306.SSD1306;import java.io.IOException;import java.util.HashMap;import java.util.TimerTask;public class minorproj extends TimerTask {static String recLog = "\"/dev/cu.usbserial-0001\"";static IODevice myGroveBoard;private final SSD1306 theOledObject;private Pin MoistureSensor;private Pin WaterPump;private Pin Button;private int sampleCount;public minorproj(SSD1306 theOledObject, Pin Button, Pin MoistureSensor, Pin WaterPump) {this.theOledObject = theOledObject;this.Button = Button;this.MoistureSensor = MoistureSensor;this.WaterPump = WaterPump;this.sampleCount = 0;}double startTime = System.currentTimeMillis();@Overridepublic void run() {while (true) {{// check if button is pressedif (this.Button.getValue() == 1) {break; // exit loop and stop program}String VolValue = String.valueOf(MoistureSensor.getValue());System.out.println("Moisture Sensor Value:" +…arrow_forward
- Ask the user for a filename. Display the oldest car for every manufacturer from that file. If two cars have the same year, compare based on the VIN. I am having trouble with my code here is my code import java.util.Comparator;import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;class Car {String manufacturer;String model;int year;String vin;public Car(String manufacturer, String model, int year, String vin) {super();this.manufacturer = manufacturer;this.model = model;this.year = year;this.vin = vin;}public String getManufacturer() {return manufacturer;}public void setManufacturer(String manufacturer) {this.manufacturer = manufacturer;}public String getModel() {return model;}public void setModel(String model) {this.model = model;}public int getYear() {return year;}public void setYear(int year) {this.year = year;}public String getVin() {return vin;}public void setVin(String vin) {this.vin = vin;}}class…arrow_forwardCreate an Ordered Doubly Linked List in C++. Remember that an ordered Linked List is one where inserts automatically place a new node so that all the nodes retain a certain order. This list should be templated where items should be in "ascending" order (i.e., if it is a list of numbers, it should be of order of least to greatest).arrow_forwardExplain the functionality of each line of code in the provided C# scripts- using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI; public class Healthbar : MonoBehaviour{ [SerializeField] private Health playerHealth; [SerializeField] private Image totalHealthbar; [SerializeField] private Image currentHealthbar; private void Start() { totalHealthbar.fillAmount = playerHealth.currentHealth / 10; } private void Update() { currentHealthbar.fillAmount = playerHealth.currentHealth / 10; }} using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.SceneManagement; public class Health : MonoBehaviour{ [SerializeField] private float startingHealth; public float currentHealth { get; private set; } private Animator anim; private void Awake() { currentHealth = startingHealth; anim = GetComponent<Animator>(); } public void…arrow_forward
- import java.util.Scanner; public class CharMatch { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String userString; char charToFind; int strIndex; userString = scnr.nextLine(); charToFind = scnr.next().charAt(0); strIndex = scnr.nextInt(); /* Your code goes here */ }}arrow_forwardAsk the user for a filename. Display the oldest car for every manufacturer from that file. If two cars have the same year, compare based on the VIN. I am having trouble with a specific line of my code here is my code import java.util.Comparator; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; class Car { String manufacturer; String model; int year; String vin; public Car(String manufacturer, String model, int year, String vin) { super(); this.manufacturer = manufacturer; this.model = model; this.year = year; this.vin = vin; } public String getManufacturer() { return manufacturer; } public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getVin() { return vin;…arrow_forwardIf we want to filter out the results and shows only the values of certain properties, such as Name, Status of Get-Service cmdlet, we can use this cmdlet: Group of answer choices Remove-Item Select-String Select-Object Sort-Objectarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education