package com.company.dao;

創(chuàng)新互聯(lián)于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元塔河做網(wǎng)站,已為上家服務(wù),為塔河各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220
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 {
// 數(shù)據(jù)庫(kù)驅(qū)動(dòng)
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//url
String url = "jdbc:sqlserver://數(shù)據(jù)庫(kù)ip:端口號(hào);databaseName=數(shù)據(jù)庫(kù)名;";
//用戶名
String uname = "數(shù)據(jù)庫(kù)用戶名";
//密碼
String pwd = "數(shù)據(jù)庫(kù)密碼";
/**
* 獲得連接對(duì)象
* @return
*/
protected Connection getCon(){
//返回的連接
Connection con = null;
try {
//載入驅(qū)動(dòng)
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;
}
/**
* 關(guān)閉數(shù)據(jù)庫(kù)
* @param con
* @param stmt
* @param rs
*/
protected void closeDB(Connection con, Statement stmt, ResultSet rs){
if(rs != null){
try {
//關(guān)閉結(jié)果集
rs.close();
rs = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stmt != null){
try {
//關(guān)閉語(yǔ)句對(duì)象
stmt.close();
stmt = null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(con != null){
try {
//關(guān)閉連接對(duì)象
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
protected void closeDB(Connection con, PreparedStatement pstmt, ResultSet rs){
if(rs != null){
//關(guān)閉結(jié)果集
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();
}
}
}
這個(gè)是我寫的一個(gè)基本的連接sql2005數(shù)據(jù)庫(kù)的代碼,.! 不知道你能不能用,! 你看一下吧, 連接的時(shí)候需要sqljdbc.jar數(shù)據(jù)庫(kù)驅(qū)動(dòng),!
既然是商品庫(kù)存系統(tǒng),那么最少有各種商品的單件信息,1:需要有商品的進(jìn)貨價(jià)格,賣出價(jià)格,剩余數(shù)量,每月的銷售數(shù)量,進(jìn)貨時(shí)間等,在對(duì)應(yīng)的數(shù)據(jù)庫(kù)表創(chuàng)建相應(yīng)的字段。2:商品管理就是對(duì)多種商品的管理,所以還要有各種商品的分類,比如煙酒類,飲料類,小吃類,將其分類好管理,同樣數(shù)據(jù)庫(kù)里面建立相對(duì)的數(shù)據(jù)表。具體需要根據(jù)自己需求來(lái)編寫。3:界面的設(shè)計(jì),這里可分為登陸界面,其中一個(gè)是用戶登陸后查看的界面,和管理員登陸后查看的界面,用戶登錄只能查看對(duì)應(yīng)的商店的物品管理,并且能進(jìn)行修改自家商品。管理員登陸可查看所有的用戶的商店物品,及修改物品信息。而物品分類欄就可以用jQuery來(lái)實(shí)現(xiàn)局部的刷新界面。左邊為物品分類欄,右邊為選中物品類的信息。點(diǎn)擊右邊分類物品的某件物品,可跳轉(zhuǎn)到該類物品的單個(gè)信息,如第1點(diǎn)提到的。
package?c;
import?java.util.Scanner;
public?class?SuperMarket?{
static?Scanner?scan?=?new?Scanner(System.in);
public?static?String?str;
public?static?void?main(String[]?args)?{
showMsg();
while?(scan.hasNext())?{
switch?(scan.nextInt())?{
case?1:
commodityManage();
break;
case?2:
customerManage();
break;
case?3:
orderManage();
break;
case?4:
exitSystem();
break;
default:
System.out.println("輸入錯(cuò)誤,請(qǐng)重新輸入!");
break;
}
}
scan.close();
}
/**
?*?顯示信息
?*/
public?static?void?showMsg()?{
System.out.println("===================================");
System.out.println("\t超??市??庫(kù)??存??管??理??系??統(tǒng)\t");
System.out.println("===================================");
System.out.println("1、商品管理");
System.out.println("2、客戶管理");
System.out.println("3、訂單管理");
System.out.println("4、退出系統(tǒng)");
System.out.println("===================================");
System.out.println("請(qǐng)輸入您的選擇(1-4):");
}
/**
?*?選項(xiàng)?1、商品管理
?*/
public?static?void?commodityManage()?{
str?=?"商品管理";
showWelcom(str);
System.out.println("以上為商品管理的信息!\n是否繼續(xù)?(按1繼續(xù)/其他結(jié)束):");
exitOrShow(1);
}
/**
?*?選項(xiàng)?2、客戶管理
?*/
public?static?void?customerManage()?{
str?=?"客戶管理";
System.out.println("以上為客戶管理的信息!\n是否繼續(xù)?(按2繼續(xù)/其他結(jié)束):");
exitOrShow(2);
}
/**
?*?選項(xiàng)?3、訂單管理
?*/
public?static?void?orderManage()?{
str?=?"訂單管理";
System.out.println("以上為訂單管理的信息!\n是否繼續(xù)?(按3繼續(xù)/其他結(jié)束):");
exitOrShow(3);
}
/**
?*?選項(xiàng)?4、退出系統(tǒng)
?*/
public?static?void?exitSystem()?{
System.exit(0);
}
public?static?void?showWelcom(String?str)?{
System.out.println("歡迎進(jìn)入"+?str?+"模塊");
System.out.println("===================================");
}
public?static?void?exitOrShow(int?nextInt)?{
if?(scan.nextInt()?!=?nextInt)?{
exitSystem();
}?else?{
showMsg();
}
}
}
網(wǎng)站標(biāo)題:java商品管理源代碼,java食品庫(kù)存管理源代碼
文章地址:http://chinadenli.net/article0/dsejeoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、定制開(kāi)發(fā)、靜態(tài)網(wǎng)站、電子商務(wù)、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)