
正文
商品管理java代码 java商品入库程序设计
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用JAVA编程的通过SQL连接数据库的商品库存管理系统的源代码
package com.company.dao;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class BaseDao {
// 数据库驱动
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//url
String url = "jdbc:sqlserver://数据库ip:端口号;databaseName=数据库名;";
//用户名
String uname = "数据库用户名";
//密码
String pwd = "数据库密码";
/**
* 获得连接对象
* @return
*/
protected Connection getCon(){
//返回的连接
Connection con = null;
try {
//载入驱动
Class.forName(driver);
//得到连接
con = DriverManager.getConnection(url, uname, pwd);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
/**
* 关闭数据库
* @param con
* @param stmt
* @param rs
*/
protected void closeDB(Connection con, Statement stmt, ResultSet rs){
if(rs != null){
try {
//关闭结果集
rs.close();
rs = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stmt != null){
try {
//关闭语句对象
stmt.close();
stmt = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(con != null){
try {
//关闭连接对象
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
protected void closeDB(Connection con, PreparedStatement pstmt, ResultSet rs){
if(rs != null){
//关闭结果集
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt != null){
try {
pstmt.close();
pstmt = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con != null){
try {
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
这个是我写的一个基本的连接sql2005数据库的代码,.! 不知道你能不能用,! 你看一下吧, 连接的时候需要sqljdbc.jar数据库驱动,!
相关问答
Q1: 帮我看一下,我的java代码。为什么运行结果不对!如图:请详解,为什么其他组件没有显示?
看注释:
import java.awt.GridLayout;
import javax.swing.*;
public class LoadForm extends JFrame{
private JPanel jpanel1;
private JTextField jtext1;
private JPasswordField password;
private JLabel jlable1;
private JLabel jlable2;
private JButton button1;
private JButton button2;
public LoadForm()
{
super("商品管理系统");
this.setLayout(null);
GridLayout layout=new GridLayout(3,3,10,10);//这句保留
jpanel1=new JPanel();
//jpanel1.setLayout(null);//jpanel1的布局不能为空
jlable1=new JLabel("用户名");
jlable2=new JLabel("密 码");
jtext1=new JTextField();
password=new JPasswordField();
button1=new JButton("确定");
button2=new JButton("取消");
jpanel1.add(jlable1);
jpanel1.add(jtext1);
jpanel1.add(jlable2);
jpanel1.add(password);
jpanel1.add(button1);
jpanel1.add(button2);
//this.add(jpanel1);//写法错误
this.setContentPane(jpanel1);//设置jpanel1为Frame的内容面版
this.setBounds(200,200,100,100);
//this.setSize(200,200);
this.setVisible(true);
}
//main方法测试
public static void main(String args[]){
new LoadForm();
}
}
Q2: 求java编写的仓库管理系统源代码或详细设计
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
class 商品 extends Panel
{String 代号,名称;int 库存;float 单价;
商品(String 代号,String 名称,int 库存,float 单价)
{this.代号=代号;this.名称=名称;this.库存=库存;this.单价=单价;
}
}
class ShowWin extends JFrame implements ActionListener
{ Hashtable hashtable=null;
JTextField 代号文本框=new JTextField(),
名称文本框=new JTextField(),
库存文本框=new JTextField(),
单价文本框=new JTextField(),
查询文本框=new JTextField(),
查询信息文本框=new JTextField(),
删除文本框=new JTextField();
JButton b_add=new JButton("添加商品"),
b_del=new JButton("删除商品"),
b_xun=new JButton("查询商品"),
b_xiu=new JButton("修改商品"),
b_show=new JButton("显示商品清单");
JTextArea 显示区=new JTextArea(25,10);
ShowWin()
{super("仓库管理窗口");
hashtable=new Hashtable();
Container con=getContentPane();
JScrollPane pane=new JScrollPane(显示区);
显示区.setEditable(false);
JPanel save=new JPanel();
save.setLayout(new GridLayout(8,2));
save.add(new Label("输入代号:"));
save.add(代号文本框);
save.add(new Label("输入名称:"));
save.add(名称文本框);
save.add(new Label("输入库存:"));
save.add(库存文本框);
save.add(new Label("输入单价:"));
save.add(单价文本框);
save.add(new Label("单击添加:"));
save.add(b_add);
save.add(new Label("单击修改:"));
save.add(b_xiu);
save.add(new Label("输入查询代号:"));
save.add(查询文本框);
save.add(new Label("单击查询:"));
save.add(b_xun);
JPanel del=new JPanel();
del.setLayout(new GridLayout(2,2));
del.add(new Label("输入删除的代号:"));
del.add(删除文本框);
del.add(new Label("单击删除:"));
del.add(b_del);
JPanel show=new JPanel();
show.setLayout(new BorderLayout());
show.add(pane,BorderLayout.CENTER);
show.add(b_show,BorderLayout.SOUTH);
JSplitPane split_one,split_two;
split_one=new JSplitPane(JSplitPane.VERTICAL_SPLIT,save,del);
split_two=new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split_one,show);
con.add(split_two,BorderLayout.CENTER);
JPanel xun=new JPanel();
xun.add(new Label("所得信息:"));
xun.add(查询信息文本框);
xun.setLayout(new GridLayout(2,1));
con.add(xun,BorderLayout.SOUTH);
b_add.addActionListener(this);
b_del.addActionListener(this);
b_xun.addActionListener(this);
b_xiu.addActionListener(this);
b_show.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b_add)
{String daihao=null,mingcheng=null;int kucun=0;float danjia=0.0f;
daihao=代号文本框.getText();mingcheng=名称文本框.getText();
kucun=Integer.parseInt(库存文本框.getText());
danjia=Float.valueOf(单价文本框.getText()).floatValue();
商品 goods=new 商品(daihao,mingcheng,kucun,danjia);
hashtable.put(daihao,goods);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
else if(e.getSource()==b_del)
{String daihao1=删除文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(daihao1);
{hashtable.remove(daihao1);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_xun)
{ String aa;
aa=查询文本框.getText();
查询信息文本框.setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 a=(商品)hashtable.get(aa);
查询信息文本框.setText(" 代号:"+a.代号+" 名称:"+a.名称+" 库存:"+a.库存+" 单价:"+a.单价);
}
//
else if(e.getSource()==b_xiu)
{ String bb;
bb=代号文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(bb);
{hashtable.remove(bb);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
String daihao1=null,mingcheng1=null;int kucun1=0;float danjia1=0.0f;
daihao1=代号文本框.getText();mingcheng1=名称文本框.getText();
kucun1=Integer.parseInt(库存文本框.getText());
danjia1=Float.valueOf(单价文本框.getText()).floatValue();
商品 goods1=new 商品(daihao1,mingcheng1,kucun1,danjia1);
hashtable.put(daihao1,goods1);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_show)
{ 显示区.setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
}
catch(ClassNotFoundException event){}
catch(IOException event){}
Enumeration enum=hashtable.elements();
while(enum.hasMoreElements())
{ 商品 te=(商品)enum.nextElement();
显示区.append("商品代号:"+te.代号+" ");
显示区.append("商品名称:"+te.名称+" ");
显示区.append("商品库存:"+te.库存+" ");
显示区.append("商品单价:"+te.单价+" ");
显示区.append("\n ");
}
}
}
}
public class LinkListFour
{public static void main(String args[])
{ ShowWin win=new ShowWin();
win.setSize(400,350);
win.setVisible(true);
win.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{ System.exit(0);}});
}
}
Q3: 商品信息管理系统如何用java写搜索商品各类信息?能否写出详细的代码
详细代码写出来很长,我写一个思路
1:前台传商品名称,类别,价格等多个属性信息
2:将这些信息放在map里面
3:迭代map,组成sql语句
String where = "where 1=1";
//迭代map
最后得出的where条件就是 where 1=1 or name='xxx' or age=xx or xx=xx
就可以搜索到前台需要的商品
Q4: 用java编写的商品库存管理系统的设计思路以及源代码是什么?
既然是商品库存系统商品管理java代码,那么最少有各种商品商品管理java代码的单件信息,1:需要有商品的进货价格,卖出价格,剩余数量,每月的销售数量,进货时间等,在对应的数据库表创建相应的字段。2:商品管理就是对多种商品的管理,所以还要有各种商品的分类,比如烟酒类,饮料类,小吃类,将其分类好管理,同样数据库里面建立相对的数据表。具体需要根据自己需求来编写。3:界面的设计,这里可分为登陆界面,其中一个是用户登陆后查看的界面,和管理员登陆后查看的界面,用户登录只能查看对应的商店的物品管理,并且能进行修改自家商品。管理员登陆可查看所有的用户的商店物品,及修改物品信息。而物品分类栏就可以用jQuery来实现局部的刷新界面。左边为物品分类栏,右边为选中物品类的信息。点击右边分类物品的某件物品,可跳转到该类物品的单个信息,如第1点提到的。
Q5: 想用JAVA敲一段商品管理员的程序,有登录账号和密码,然后可以添加和删除商品的功能?
项目:完成一个电商系统的商品模块功能,商品类包含以下属性:商品ID, 商品名,类别名,单价,库存量,产地,计量单位等信息,要求实现商品管理功能以及管理员功能,具体如下:
1.管路员登录(账号密码固定admin/admin)
2.修改管理员密码
3.商品添加
4.商品列表
5.查询指定id商品
6.根据商品id删除商品
7.根据id修改商品价格
8.根据id修改指定商品库存
9.根据商品类别查询所有商品
10.查询指定价格区间的商品信息
根据项目要求,我们首先分析题目,知道此项目至少四个类:管理员类、商品类、系统类、测试类。
由于我们决定对此系统进行优化,要求能够对数据进行保存,所以我们用流的相关知识,将数据写入已经创建好的文档中,使其自动读写,以便管理,三个文档分别用于保存商品信息、id、user。
商品管理java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java商品入库程序设计、商品管理java代码的信息别忘了在本站进行查找喔。








