jsp以及JDBC总结复习

html:
form
action method

jsp:
request.getParameter
request.setCharacterEncoding
session.setArrtribute

jdbc:
update set
inset into values

Shipping数据库关系
用户和购物车一对多
购物车和购物选项是一对多
在多的关系中存入关系一的ID就行了

order.jsp
就是List里面放着商品
xiadan.jsp
新new一个订单,写入数据库,再写入odersaleitem


JDBC

package com.jingtian.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DB {

	public static Connection getConn() {
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");//定义连接URL
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shopping2", "root", "124343");//与数据库建立链接
//			con = DriverManager.getConnection("jdbc:mysql://117.25.156.167:3306/sq_xiaozhi","sq_xiaozhi", "a83twx");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}

	public static Statement getStatement(Connection con) {
		Statement stm = null;
		try {
			stm = con.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return stm;
	}

	public static ResultSet executeQuery(String str,Statement stm) {
		ResultSet rs = null;
		try {
			rs = stm.executeQuery(str);
			return rs;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static int executeUpdate(String str,Statement stm) {
		ResultSet rs = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			int i = stm.executeUpdate(str);
			return i;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;
	}

	public static void close(Connection conn) {
		try {
			if (conn != null) {
				conn.close();
				conn = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void close(Statement stmt) {
		try {
			if (stmt != null) {
				stmt.close();
				stmt = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void close(ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}


你可能感兴趣的:(我的小项目,JavaWeb,MySQL和JDBC)