📄 store01.java
字号:
// BegJavaDB/Ch06/connections/Store01.java
package connections;
import java.sql.*;
/**
* A class to represent a retail store in the Music system.
*/
public class Store01 {
int storeId;
String storeDescription = "";
int storeTypeId;
String storeAddress1 = "";
String storeAddress2 = "";
String storeCity = "";
String storePostalCode = "";
// constructor
public Store01() {}
// constructor
public Store01(String description, int typeId, String address1,
String address2, String city, String postalCode) {
storeDescription = description;
storeTypeId = typeId;
storeAddress1 = address1;
storeAddress2 = address2;
storeCity = city;
storePostalCode = postalCode;
}
/**
* Create an entry in the database for this object.
*/
public boolean create() {
int result = 0;
Connection connection = null;
Statement statement = null;
try {
// Load the Driver class file, and create an instance of the class
// Creating an instance causes the driver to register with the
// DriverManager
Class.forName("COM.cloudscape.core.JDBCDriver");
// Create a url for the database and...
String url = "jdbc:cloudscape:c:/wrox/database/Wrox4370.db";
// ...connect to the database
connection = DriverManager.getConnection(url);
statement = connection.createStatement();
String sql = "INSERT INTO stores " +
"(StoreDescription, StoreTypeID, StoreAddress1, " +
"StoreAddress2, StoreCity, StorePostalCode) " +
"VALUES ('" + getStoreDescription() + "', " +
getStoreTypeId() + ", " + "'" + getStoreAddress1() +
"', " + "'" + getStoreAddress2() + "', " + "'" +
getStoreCity() + "', " + "'" + getStorePostalCode() +
"')";
result = statement.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
return (result == 1);
}
public int getStoreId() {
return storeId;
}
public String getStoreDescription() {
return storeDescription;
}
public void setStoreDescription(String v) {
storeDescription = v;
}
public String getStoreAddress1() {
return storeAddress1;
}
public void setStoreAddress1(String v) {
storeAddress1 = v;
}
public String getStoreAddress2() {
return storeAddress2;
}
public void setStoreAddress2(String v) {
storeAddress2 = v;
}
public int getStoreTypeId() {
return storeTypeId;
}
public void setStoreTypeId(int v) {
storeTypeId = v;
}
public String getStoreCity() {
return storeCity;
}
public void setStoreCity(String v) {
storeCity = v;
}
public String getStorePostalCode() {
return storePostalCode;
}
public void setStorePostalCode(String v) {
storePostalCode = v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -