📄 condb.java
字号:
package dao;
import java.sql.*;
import java.util.ArrayList;
import bean.ItemBean;
import bean.UserBean;
public class ConDB {
private Statement stm;
public ConDB()
{
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/shopping","root", "mysql");
stm=conn.createStatement();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ArrayList getItemAll()
{
ArrayList list=new ArrayList();
ResultSet rs;
try {
rs = stm.executeQuery("select * from shopping");
while(rs.next())
{
ItemBean ib=new ItemBean();
ib.setShopname(rs.getString("shopname"));
ib.setShopvalue(Integer.parseInt(rs.getString("shopvalue")));
ib.setShopnum(Integer.parseInt(rs.getString("shopnum")));
ib.setShopfactory(rs.getString("shopfactory"));
ib.setShopdate(rs.getString("shopdate"));
ib.setShopclass(rs.getString("shopclass"));
ib.setShopid(Integer.parseInt(rs.getString("shopid")));
list.add(ib);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("size="+list.size());
return list;
}
public ItemBean getItem(int name)
{
ItemBean ib=new ItemBean();
ResultSet rs;
System.out.println(name);
try {
rs = stm.executeQuery("select * from shopping where shopid='"+name+"'");
while(rs.next())
{
ib.setShopname(rs.getString("shopname"));
ib.setShopvalue(Integer.parseInt(rs.getString("shopvalue")));
ib.setShopnum(Integer.parseInt(rs.getString("shopnum")));
ib.setShopfactory(rs.getString("shopfactory"));
ib.setShopdate(rs.getString("shopdate"));
ib.setShopclass(rs.getString("shopclass"));
String ss=rs.getString("shopid");
int ii = Integer.parseInt(ss);
ib.setShopid(ii);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ib;
}
public ArrayList getClassAll()
{
ArrayList list=new ArrayList();
ResultSet rs;
try {
rs = stm.executeQuery("select * from shopping");
while(rs.next())
{
list.add(rs.getString("shopclass"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public int getUserAll(String name,String pass)
{
int b=-1;
ResultSet rs;
try {
rs = stm.executeQuery("select * from shopping_login where uname='"+name+"' and upass='"+pass+"'");
rs.next();
Integer i=Integer.parseInt(rs.getString(("grade")));
b=i.intValue();
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
public void addUserAll(UserBean bean)
{
try {
stm.executeUpdate("insert into shopping_login");
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -