資源簡介
商店商品管理系統 JAVA寫的 有界面 商品管理 需要自己設計數據庫 很簡單
代碼片段和文件信息
import?java.sql.*;
import?java.util.ArrayList;
public?class?DBConnection?{
private?Connection?connection;
private?Statement?statement;
private?ResultSet?resultset;
private?ArrayList?useridlist;
String?username;
String?password;
int?state;
boolean?hasuser;
public?DBConnection(){
try{
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver“);
connection?=?this.getconnection();
if(connection!=null){
System.out.print(“數據庫鏈接成功!“);
}
}
catch(Exception?e){
e.printStackTrace();
}
}
public??Connection?getconnection()?throws?SQLException{
String?url=“jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=C1UserEclipse“;
String?username=“sa“;
String?password=“384“;
return?DriverManager.getConnection(urlusername?password);
?????????}
public?void?close(){
try{
if(resultset!=null){
resultset.close();
}
else?if(statement!=null){
statement.close();
}
else?if(connection!=null){
connection.close();
}
}catch(Exception?e){
e.printStackTrace();
}
}
public?void?adduser(String?usernameString?passwordint?state){
?????Connection?conn=null;
?????PreparedStatement?stmt=null;
?????try{
???? ?conn=getconnection();
???? ?String?sql1=“insert?into?usertable(userNameuserPassworduserState)?values(‘“+username+“‘‘“+password+“‘‘“+state+“‘)“;
???? ?stmt=conn.prepareStatement(sql1);
???? ?stmt.executeUpdate();
?????}catch(SQLException?e){
???? e.printStackTrace();
?????}
??}
public?ArrayList?showuserid(){
Connection?conn=null;
Statement?stmt=null;
ResultSet?result?=?null;
useridlist?=?new?ArrayList();
try{
conn=getconnection();
String?sql2=“select?userId?from?usertable“;
stmt?=?conn.createStatement();
result?=?stmt.executeQuery(sql2);
while(result.next()){
useridlist.add(result.getInt(“userId“));
}
}catch(SQLException?e){
e.printStackTrace();
}
return?useridlist;
}
public?String?showusername(int?userid){
try{
Connection?conn=getconnection();
String?sql3=“select?userName?from?usertable?where?userId=“+userid;
Statement?stmt=conn.createStatement();
ResultSet?result=stmt.executeQuery(sql3);
if(result.next()){
username?=?result.getString(“userName“);
}
}catch(SQLException?e){
e.printStackTrace();
}
return?username;
}
public?String?showpassword(int?userid){
try{
Connection?conn=getconnection();
String?sql4=“select?userPassword?from?usertable?where?userId=“+userid;
Statement?stmt=conn.createStatement();
ResultSet?result=stmt.executeQuery(sql4);
if(result.next()){
password?=?result.getString(“userPassword“);
}
}catch(SQLException?e){
e.printStackTrace();
}
return?password;
}
public?int?showstate(int?userid){
try{
Connection?conn=getconnection();
String?sql4=“select?userState?from?usertable?where?userId=“+userid;
Statement?stmt
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????382??2009-10-27?22:01??Border\.project
?????文件???????5008??2009-11-07?10:51??Border\src\usermanagement.java
?????文件???????6778??2009-11-09?19:41??Border\src\Restockfr
?????文件???????2455??2009-11-05?12:48??Border\src\Demon.java
?????文件???????4473??2009-11-08?09:19??Border\src\DBConnection.java
?????文件???????7796??2009-11-09?19:33??Border\src\RestockQueryfr
?????文件???????2935??2009-11-09?15:57??Border\src\QuerDBConnection.java
?????文件???????3177??2009-11-09?19:12??Border\src\RDBConnection.java
?????文件???????1571??2009-11-09?15:25??Border\src\Message.java
?????文件???????8121??2009-11-09?20:04??Border\src\RQueryshfr
?????文件???????6407??2009-11-09?12:34??Border\bin\usermanagement.class
?????文件????????672??2009-11-09?12:34??Border\bin\usermanagement$1.class
?????文件????????690??2009-11-09?19:33??Border\bin\RestockQueryfr
?????文件???????9141??2009-11-09?19:33??Border\bin\RestockQueryfr
?????文件????????660??2009-11-09?19:41??Border\bin\Restockfr
?????文件???????8143??2009-11-09?19:41??Border\bin\Restockfr
?????文件???????4528??2009-11-09?19:12??Border\bin\RDBConnection.class
?????文件???????3536??2009-11-09?15:57??Border\bin\QuerDBConnection.class
?????文件???????2272??2009-11-09?15:25??Border\bin\Message.class
?????文件????????618??2009-11-09?12:34??Border\bin\Demon$1.class
?????文件???????3671??2009-11-09?12:34??Border\bin\Demon.class
?????文件???????5656??2009-11-09?12:34??Border\bin\DBConnection.class
?????文件???????9363??2009-11-09?20:04??Border\bin\RQueryshfr
?????文件????????666??2009-11-09?20:04??Border\bin\RQueryshfr
?????文件????????573??2009-11-03?15:52??Border\.classpath
?????目錄??????????0??2009-10-27?22:01??Border\src
?????目錄??????????0??2009-10-27?22:01??Border\bin
?????目錄??????????0??2009-10-27?22:01??Border
-----------?---------??----------?-----??----
????????????????99292????????????????????28
............此處省略1個文件信息
- 上一篇:基于JSP的校友信息管理系統(添加數據文件版)
- 下一篇:Jsp購物車實例
評論
共有 條評論