?? booktype.java
字號:
/**
@forlink 2006-2
*/
import java.sql.*;
public class BookType
{
private Statement bookT;
private String id; /*書架類型的唯一標識,對應數據庫的ID*/
private String name; /* 圖書類型名*/
public BookType()
{
}
/**
Access method for the id property.
@return the current value of the id property
*/
public String getId()
{
return id;
}
/**
Sets the value of the id property.
@param aId the new value of the id property
*/
public void setId(String aId)
{
id = aId;
}
/**
Access method for the name property.
@return the current value of the name property
*/
public String getName()
{
return name;
}
/**
Sets the value of the name property.
@param aName the new value of the name property
*/
public void setName(String aName)
{
name = aName;
}
static int mode = 1;
static String sID = "TP312";
static String sName = "計算機";
/**
書架查詢
*/
public void SelectBT(int Mode)
{
mode = Mode;
sID = id;
sName = name;
try
{
DbConnect driver = new DbConnect();
BookType query = new BookType ();
ResultSet rs;
String sqlCommand = "";
driver.setURL("jdbc:odbc:book");
driver.setUser("");
driver.setPassword("");
Connection con = driver.getConnection();
query.setStatement(con);
if(mode == 1) /*按ID查詢*/
{
sqlCommand = "select * from BookType where id = '" + sID + "'" ;
}
else
if(mode == 2) /*按name查詢*/
{
sqlCommand = "select * from BookType where name = '" + sName + "'";
}
rs = query.executeQuery(sqlCommand);
rs.next();
System.out.println("查詢結果如下:");
System.out.println("ID \t" + "Name \t\t" + "valid_flag" + "\t" + "UpDate_time");
for(int i = 0; i<rs.getRow(); i++)
{
System.out.println(rs.getString("id") + "\t" + rs.getString("name") +"\t\t" +
rs.getString("valid_flag") + "\t" + rs.getString("update_time"));
rs.next();
}
rs.close();
query.closeStatement();
con.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
public void setStatement(Connection con)
{
try
{
this.bookT = con.createStatement();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
public ResultSet executeQuery(String sqlCommand)
{
try
{
return bookT.executeQuery(sqlCommand);
}
catch (Exception e)
{
System.out.println(e.toString());
}
return null;
}
public void closeStatement()
{
try
{
bookT.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
書架更新
*/
static String uID="" ;
static String uName="" ;
public void UpdateBT(String id,String name)
{
uID=id ;
uName=name ;
try
{
DbConnect driver=new DbConnect();
BookType update=new BookType ();
ResultSet rs;
String sqlCommand;
driver.setURL("jdbc:odbc:book");
driver.setUser("");
driver.setPassword("");
Connection con=driver.getConnection();
update.setStatement(con);
sqlCommand="UPDATE BookType SET name='"+uName+"' where id ='"+uID+"'";
rs=update.executeQuery(sqlCommand);
sqlCommand = "select * from BookType" ;
rs=update.executeQuery(sqlCommand);
rs.next();
System.out.println("更新結果如下:");
System.out.println("ID \t" + "Name \t\t" + "valid_flag" + "\t" + "UpDate_time");
for(int i = 0; i<rs.getRow(); i++)
{
System.out.println(rs.getString("id") + "\t" + rs.getString("name") +"\t\t" +
rs.getString("valid_flag") + "\t" + rs.getString("update_time"));
rs.next();
}
rs.close();
update.closeStatement();
con.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -