📄 album.java
字号:
/*
* Copyright (c) 2000 Javacat. All Rights Reserved.
*
* @(#)Album.java 12/10/2000
*/
package com.javacat.jsp.beans.ebiz;
import javax.servlet.http.*;
import java.util.Vector;
import java.util.Enumeration;
import java.sql.*;
/**
*The Cart bean is used as a dummy cart for client
*to hold their goods when they're shopping online.
*/
public class Album{
//fields
static String dbs="jdbc:odbc:CDcollection";
int id;
String albumName;
String artist;
String cover;
String price;
String description;
static{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(Exception e){
e.printStackTrace();
}
}
public Album()
{
super();
}
public Album(int id)
{
this();
this.setID(id);
this.init();
}
public void setID(int id)
{
this.id=id;
}
public int getID()
{
return this.id;
}
public String[] getSongs()
{
String[] songs={""};
if(getID()>=0){
Vector vic=new Vector();
try{
Connection con=DriverManager.getConnection(dbs);
PreparedStatement ps=con.prepareStatement("SELECT name FROM song WHERE id=?");
ps.setInt(1,this.id);
ResultSet res=ps.executeQuery();
while(res.next()){
vic.add(res.getString(1));
}
}catch(SQLException se)
{
return new String[]{""};
}
if(vic.size()>0){
songs=new String[vic.size()];
vic.copyInto(songs);
}
}//if id>=0
return songs;
}
void init(){
try{
Connection con=DriverManager.getConnection(dbs);
PreparedStatement ps=con.prepareStatement("SELECT * FROM album WHERE id=?");
ps.setInt(1,this.id);
ResultSet res=ps.executeQuery();
if(res.next()){
this.setAlbumName(res.getString(2));
this.setArtist(res.getString(3));
this.setPrice(res.getString(4));
this.setCover(res.getString(5));
if(res.getString(6)!=null)
this.setDescription(res.getString(6));
}//res next
else this.id=-1;
con.close();
}catch(SQLException sqle)
{
this.id=-1;
}
}//init()
public void setArtist(String name)
{
this.artist=name;
}
public String getArtist()
{
return this.artist;
}
public void setCover(String coverImg)
{
this.cover=coverImg;
}
public String getCover()
{
return this.cover;
}
public void setPrice(String price)
{
this.price=price;
}
public String getPrice()
{
return this.price;
}
public void setAlbumName(String name)
{
this.albumName=name;
}
public String getAlbumName()
{
return this.albumName;
}
public void setDescription(String s)
{
this.description=s;
}
public String getDescription()
{
return this.description;
}
public static Album[] ListAlbum()
{
Vector result=new Vector(10,5);
try{
Connection con=DriverManager.getConnection(dbs);
Statement ps=con.createStatement();
ResultSet res=ps.executeQuery("SELECT * FROM album");
while(res.next()){
Album album=new Album();
album.setID(res.getInt(1));
album.setAlbumName(res.getString(2));
album.setArtist(res.getString(3));
album.setPrice(res.getString(4));
album.setCover(res.getString(5));
result.add(album);
}//res next
con.close();
}catch(SQLException se){}
Album[] albums=new Album[result.size()];
result.copyInto(albums);
return albums;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -