此商品管理系统是在myeclipse控制台实现的商品增删改查操作,较为普通,不是web端项目的那种,只能作为平时的实验,如果是课程设计的话应该制作web端那种。
项目建立了一个包为System2,其中有两个class文件,分别为ShopSystem.java和Test.java。
以下代码为ShopSystem.java的内容
package System2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ShopSystem {
public void insertShop(int id,String name,String introduce){ //插入
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "111");
// 创造SQL语句
String sql = "INSERT INTO shop(id,name,introduce) VALUES ('"+id+"' ,'"+name+"', '"+introduce+"' )";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}catch(Exception e){
e.printStackTrace();
}finally{
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
conn.close(