购物车这个和你登陆差不多啦,点击加入购物车的时候传商品的id,用户的id,商品数量等信息,加入到数据库里就行了
连接数据库的典型步骤
第一步:加载正确的数据库驱动程序
第二步,定义所要连接数据库的地址
StringODBCURL=“jdbc:odbc:dbName”;
StringoracleURL="jdbc:oracle:thin:@host:port:dbName“;
StringmysqlURL="jdbc:mysql://host:port/dbName“;
StringsqlURL=“jdbc:microsoft:sqlserver://host:1433;DatabaseName=dbName”;
第三步,建立与数据库的连接
DriverManager.getConnection(oracleURL,
username,
password);
第四步,创建语句对象
Statementstatement=connection.createStatement();
Stringsql=“SELECT*FROMONTACT_TABLE”;
ResultSetresultSet=statement.executeQuery(sql);
该语句将sql命令提交给数据库服务器进行执行,并将执行结果存储在ResultSet对象中进行执行。
Statement接口主要有如下三个方法:
1.ResultSetexecuteQuery(Stringsql)
用于执行查询语句,返回ResultSet结果集(一个二维表)
2.intexecuteUpdate(Stringsql)
用于执行添加、删除或修改操作,返回被更新记录的条数
3.booleanexecute(Stringsql)
执行参数部分的SQL语句;
当SQL语句的执行结果是一个ResultSet结果集时,本方法返回true;并可以通过StatementgetResultSet()方法得到返回的结果集
当SQL语句执行后没有返回的结果集时,该方法返回false
第六步:对查询结果进行分析
while(resultSet.next()){
name=resultSet.getString(1);
phone=resultSet.getString(2);
System.out.println(name+","+phone);
}
第七步,关闭打开的资源
resultSet.close();
statement.close();
connection.close();
将打开的资源关闭。
注意:资源关闭的顺序和打开的顺序恰恰相反。
JSP网上书店这个题目不难,但是JSP基本没有免费的现成的资源可用。JSP源码+Word论文+PPT答辩全套。
javaswing登陆界面code
/*
*Login.java
*
*Createdon__DATE__,__TIME__
*/
packagecom.agen.library.window;
importjava.awt.Image;
importjava.awt.Toolkit;
importjavax.swing.JOptionPane;
importjavax.swing.UIManager;
importjavax.swing.UnsupportedLookAndFeelException;
importcom.agen.library.factory.DAOFactory;
importcom.agen.library.util.GlobalUser;
importcom.agen.library.vo.User;
/**
*@author__USER__
publicclassLoginextendsjavax.swing.JFrame{
privatestaticfinallongserialVersionUID=-2176093732040600809L;
/**CreatesnewformLogin*/
publicLogin(){
super("易云图书管理软件V1.0");
Imageime=Toolkit.getDefaultToolkit().getImage(
getClass().getResource("/images/ico.png"));
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(ClassNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(InstantiationExceptione){
}catch(IllegalAccessExceptione){
}catch(UnsupportedLookAndFeelExceptione){
setIconImage(ime);
initComponents();
setLocationRelativeTo(null);
this.setResizable(false);
*Thismethodiscalledfromwithintheconstructortoinitializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodisalways
*regeneratedbytheFormEditor.
//GEN-BEGIN:initComponents
//editor-folddefaultstate="collapsed"desc="GeneratedCode"
privatevoidinitComponents(){
jLabel2=newjavax.swing.JLabel();
jLabel3=newjavax.swing.JLabel();
jTextField1=newjavax.swing.JTextField();
jPasswordField1=newjavax.swing.JPasswordField();
jButton1=newjavax.swing.JButton();
jButton2=newjavax.swing.JButton();
jLabel1=newjavax.swing.JLabel();
jMenuBar1=newjavax.swing.JMenuBar();
jMenu1=newjavax.swing.JMenu();
jMenuItem1=newjavax.swing.JMenuItem();
jMenu2=newjavax.swing.JMenu();
jMenuItem2=newjavax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addKeyListener(newjava.awt.event.KeyAdapter(){
publicvoidkeyPressed(java.awt.event.KeyEventevt){
formKeyPressed(evt);
publicvoidkeyTyped(java.awt.event.KeyEventevt){
formKeyTyped(evt);
});
jLabel2.setFont(newjava.awt.Font("微软雅黑",0,14));
jLabel2.setText("\u7528\u6237\u540d\uff1a");
jLabel3.setFont(newjava.awt.Font("微软雅黑",0,14));
jLabel3.setText("\u5bc6\u7801\uff1a");
jTextField1.setFont(newjava.awt.Font("微软雅黑",0,14));
jTextField1.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jTextField1ActionPerformed(evt);
jPasswordField1.setFont(newjava.awt.Font("微软雅黑",0,12));
jPasswordField1.addKeyListener(newjava.awt.event.KeyAdapter(){
jPasswordField1KeyTyped(evt);
jButton1.setBackground(newjava.awt.Color(223,216,216));
jButton1.setFont(newjava.awt.Font("微软雅黑",0,14));
jButton1.setText("\u767b\u9646");
jButton1.addActionListener(newjava.awt.event.ActionListener(){
jButton1ActionPerformed(evt);
jButton2.setBackground(newjava.awt.Color(223,216,216));
jButton2.setFont(newjava.awt.Font("微软雅黑",0,14));
jButton2.setText("\u53d6\u6d88");
jButton2.addActionListener(newjava.awt.event.ActionListener(){
jButton2ActionPerformed(evt);
jLabel1.setIcon(newjavax.swing.ImageIcon(
getClass().getResource("/images/login_main.jpg")));//NOI18N
jMenu1.setText("File");
jMenu1.setFont(newjava.awt.Font("微软雅黑",0,14));
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_Q,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Exit");
jMenuItem1.addMouseListener(newjava.awt.event.MouseAdapter(){
publicvoidmouseClicked(java.awt.event.MouseEventevt){
jMenuItem1MouseClicked(evt);
jMenuItem1.addActionListener(newjava.awt.event.ActionListener(){
jMenuItem1ActionPerformed(evt);
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Help");
jMenu2.setFont(newjava.awt.Font("微软雅黑",0,14));
jMenuItem2.setText("About");
jMenuItem2.addActionListener(newjava.awt.event.ActionListener(){
jMenuItem2ActionPerformed(evt);
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(
jLabel2,
javax.swing.GroupLayout.Alignment.LEADING)
javax.swing.GroupLayout.Alignment.LEADING,
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGap(10,
10,
10)
jButton1)
.addGap(47,
47,
47)
jButton2))
jPasswordField1)
jTextField1,
javax.swing.GroupLayout.DEFAULT_SIZE,
197,
Short.MAX_VALUE))
.addContainerGap()))));
layout.setVerticalGroup(layout
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
javax.swing.GroupLayout.PREFERRED_SIZE,
24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel3)
jPasswordField1,
23,
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(
Short.MAX_VALUE)));
pack();
}///editor-fold
//GEN-END:initComponents
privatevoidjMenuItem2ActionPerformed(java.awt.event.ActionEventevt){
//TODOaddyourhandlingcodehere:
About.start();
privatevoidjPasswordField1KeyTyped(java.awt.event.KeyEventevt){
if(evt.getKeyChar()=='\n'){
Stringname=jTextField1.getText();//获取用户名
Stringpass=String.valueOf(jPasswordField1.getPassword());//获取密码
Useruser=null;
//未输入用户名
if(name.equals("")||name==null){
JOptionPane.showMessageDialog(this,"用户名不允许为空!","cuowu",0);
return;
user=DAOFactory.getIUserDAOInstance().findById(name);
if(user!=null){
if(user.getPass()!=nulluser.getPass().equals(pass)){
GlobalUser.LOGIN_USER=user;//记录当前用户
//进入主界面
Main.start();
this.dispose();
}else{
JOptionPane.showMessageDialog(this,"用户名或密码错误!");
}catch(Exceptione){
if(user==null){
JOptionPane.showMessageDialog(this,"用户名或密码错误!","消息",0);
privatevoidformKeyTyped(java.awt.event.KeyEventevt){
privatevoidformKeyPressed(java.awt.event.KeyEventevt){
privatevoidjTextField1ActionPerformed(java.awt.event.ActionEventevt){
privatevoidjButton2ActionPerformed(java.awt.event.ActionEventevt){
jTextField1.setText("");
jPasswordField1.setText("");
jTextField1.requestFocus();
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
if(name.equals("")){
JOptionPane.showMessageDialog(this,"用户名不允许为空!");
privatevoidjMenuItem1ActionPerformed(java.awt.event.ActionEventevt){
if(JOptionPane.showConfirmDialog(this,"你确定要退出吗?","提示",
JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
System.exit(0);
privatevoidjMenuItem1MouseClicked(java.awt.event.MouseEventevt){
System.exit(1);
*@paramargs
*thecommandlinearguments
publicstaticvoidmain(Stringargs[]){
//System.out.println(Login.class.getResource("src/images/images/login_main.jpg"));
//newjavax.swing.ImageIcon(
//Login.class.getResource("../../../../images/login_main.jpg"));