📄 track.java
字号:
package statements;
import java.sql.*;
public class Track {
int recordingId;
int trackNumber;
String trackTitle;
int artistId;
int styleId;
String sampleFilespec;
PreparedStatement preparedStmt;
boolean create;
boolean retrieve;
boolean update;
boolean delete;
/**
* The SQL INSERT statement used by this class for creating an entry
* in the database
*/
public static String getCreateSql() {
return "INSERT INTO TRACKS (RECORDINGID, TRACKNUMBER, TRACKTITLE, " +
"ARTISTID, STYLEID, SAMPLEFILESPEC) VALUES (?, ?, ?, ?, ?, ?)";
}
/**
* Prepare the class for creating (inserting) a row in the
* database. The PreparedStatement should be created using the SQL
* string obtained by calling the method getCreateSql() in this
* class.
*/
public void setCreateStatement(PreparedStatement ps) {
preparedStmt = ps;
create = (ps != null ? true : false);
retrieve = false;
update = false;
delete = false;
}
/** Create an entry in the database with the data held by this object */
public boolean executeSql() throws SQLException {
if (create || update || delete) {
int result = preparedStmt.executeUpdate();
return result == 1 ? true : false;
} else {
ResultSet resultSet = preparedStmt.executeQuery();
//process the ResultSet
return true;
}
}
public int getRecordingId() { return recordingId; }
/**
* Sets the recording id of this object. If an SQL statement is
* currently defined and this data is used in the statement, this
* method also sets the appropriate parameter in the method.
*/
public void setRecordingId(int v) throws SQLException {
recordingId = v;
if (create) {
preparedStmt.setInt(1, v);
}
}
public int getTrackNumber() { return trackNumber; }
public void setTrackNumber(int v) throws SQLException {
trackNumber = v;
if (create) {
preparedStmt.setInt(2, v);
}
}
public String getTrackTitle() { return trackTitle; }
public void setTrackTitle(String v) throws SQLException {
trackTitle = v;
if (create) {
preparedStmt.setString(3, v);
}
}
public int getArtistId() { return artistId; }
public void setArtistId(int v) throws SQLException {
artistId = v;
if (create) {
preparedStmt.setInt(4, v);
}
}
public int getStyleId() { return styleId; }
public void setStyleId(int v) throws SQLException {
styleId = v;
if (create) {
preparedStmt.setInt(5, v);
}
}
public String getSampleFilespec() { return sampleFilespec; }
public void setSampleFilespec(String v) throws SQLException {
sampleFilespec = v;
if (create) {
preparedStmt.setString(6, v);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -