-
MVC框架模式 :(Model View Controller 模型-視圖-控制器)
Model(模型): 模型對象負責在數據庫中存取數據。
View(視圖): 視圖是依據模型數據創建的。
Controller(控制器): 控制器負責從視圖讀取數據,控制用戶輸入,并向模型發送數據。
查看全部 -
@JDBC——JDBC簡介——JDBC獲取數據庫連接 一、三步獲取數據庫連接(需要導入mysql-connector-java-5.1.7-bin的jar包) 1.加載驅動程序: Class.forName(driverClass) 加載Mysql驅動:Class.forName("com.mysql.jdbc.Driver") 加載Oracle驅動:Class.forName("oracle.jdbc.driver.OracleDriver") ***注意:驅動是固定寫法 2.獲得數據庫連接: DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/imooc","root","root"); ***注釋:其中jdbc:mysql表示jdbc連接mysql,127.0.0.1:3306為服務器地址和端口,imooc為數據庫名稱,root分別是用戶名和密碼 3.創建Statement對象: conn.createStatement();
查看全部 -
JDBC提供了一種基準,據此可以構建更高級的工具和接口,使數據庫開發人員能夠編寫數據庫應用程序。
查看全部 -
JDBC:用于執行SQL語句的Java API,可以為多種關系數據庫提供統一訪問。 JDBC:java data base connection(java數據庫連接),可以為多種數據庫提供統一的訪問,體現:java一次編譯,到處運行。 瀏覽器輸入用戶名和密碼,username和password會傳遞到應用服務器上,服務器調用數據庫DB,把username和password傳遞到DB,查詢DB中username和password是否存在和匹配,DB返回結果以后,應用服務器分析查詢結果,如果結果正確,瀏覽器跳轉登陸成功頁面;否則返回登陸界面并提示用戶:失敗! JDBC的存在,應用服務器操作數據庫。
查看全部 -
????JDBC
加載驅動程序:Class.forName(driverClass)
加載Mysql驅動:Class.forName("com.mysql.jdbc.Driver");
加載Oracle驅動:Class.forName(“oracle.jdbc.driver.OracleDriver”)
獲得數據庫連接:
DriverMannager.getConnection("jdbc:mysaql://127.0.0.1:3306/數據庫名",root","root");
創建Statemen對象:conn》createStatement();
查看全部 -
package com.imooc.view;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import com.imooc.action.GoddessAction;
import com.imooc.model.Goddess;
public class View {
private static final String CONTEXT = "歡迎來到女神世界:\n" + "下面是女神世界的功能列表:\n"
+ "[MAIN/M]:主菜單\n" + "[QUERY/Q]:查看全部女神信息\n" + "[GET/G]:查看某個女神信息\n"
+ "[ADD/A]:添加女神信息\n" + "[UPDATE/U]:更新女神信息\n"
+ "[DELETE/D]:刪除女神信息\n" + "[SEARCH/S]:查詢女神信息(根據姓名,手機號查詢)\n"
+ "[EXIT/E]:退出女神世界\n" + "[BREAK/B]:返回主菜單";
private static final String OPERATION_MAIN = "MAIN";
private static final String OPERATION_QUERY = "QUERY";
private static final String OPERATION_GET = "GET";
private static final String OPERATION_ADD = "ADD";
private static final String OPERATION_UPDATE = "UPDATE";
private static final String OPERATION_DELETE = "DELETE";
private static final String OPERATION_SEARCH = "SEARCH";
private static final String OPERATION_EXIT = "EXIT";
private static final String OPERATION_BREAK = "BREAK";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Goddess goddess = new Goddess();
GoddessAction action = new GoddessAction();
String prenious = null;
Integer step = 1;
while (scanner.hasNext()) {
String in = scanner.next();
if (OPERATION_EXIT.equals(in.toUpperCase())
|| OPERATION_EXIT.substring(0, 1).equals(in.toUpperCase())) {
System.out.println("您已成功退出女神世界!");
break;
} else if (OPERATION_MAIN.equals(in.toUpperCase())
|| OPERATION_MAIN.substring(0, 1).equals(in.toUpperCase())) {
prenious = null;
step = 1;
System.out.println(CONTEXT);
} else if (OPERATION_BREAK.equals(in.toUpperCase())
|| OPERATION_BREAK.substring(0, 1).equals(in.toUpperCase())) {
prenious = null;
step = 1;
System.out.println("退出當前功能,返回主菜單");
System.out.println(CONTEXT);
} else if (OPERATION_QUERY.equals(in.toUpperCase())
|| OPERATION_QUERY.substring(0, 1).equals(in.toUpperCase())) {
try {
List<Goddess> list = action.query();
for (Goddess god : list) {
System.out.println(god.getId() + "? 姓名:"
+ god.getUser_name());
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (OPERATION_GET.equals(in.toUpperCase())
|| OPERATION_GET.substring(0, 1).equals(in.toUpperCase())) {
System.out.println("請輸入您要查詢的女神ID:");
Integer id = scanner.nextInt();
try {
Goddess go = action.get(id);
System.out.println(go.toString());
} catch (SQLException e) {
e.printStackTrace();
}
}
if (OPERATION_GET.equals(prenious)) {
step++;
} else if (OPERATION_UPDATE.equals(in.toUpperCase())
|| OPERATION_UPDATE.substring(0, 1)
.equals(in.toUpperCase())
|| OPERATION_UPDATE.equals(prenious)) {
prenious = OPERATION_UPDATE;
if (1 == step) {
System.out.println("請輸入的要更新的女神 ID:");
} else if (2 == step) {
goddess.setId(Integer.valueOf(in));
System.out.println("請輸入新的 【姓名】");
} else if (3 == step) {
goddess.setUser_name(in);
System.out.println("請輸入新的 【年齡】");
} else if (4 == step) {
goddess.setAge(Integer.valueOf(in));
System.out.println("請輸入新的【生日】 ;格式:yyyy-MM-dd");
} else if (5 == step) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Date birthday = null;
try {
birthday = sf.parse(in);
goddess.setBirthday(birthday);
System.out.println("請輸入新的【郵箱】");
} catch (ParseException e) {
e.printStackTrace();
System.out.println("您輸入的格式有誤,請重新輸入!");
step = 3;
}
} else if (6 == step) {
goddess.setEmail(in);
System.out.println("請輸入新的【手機號】");
} else if (7 == step) {
goddess.setMobile(in);
try {
action.edit(goddess);
System.out.println("更新女神成功!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("更新女神失?。?);
}
}
if (OPERATION_UPDATE.equals(prenious)) {
step++;
}
} else if (OPERATION_SEARCH.equals(in.toUpperCase())
|| OPERATION_SEARCH.substring(0, 1)
.equals(in.toUpperCase())) {
List<Map<String, Object>> params = new ArrayList<Map<String, Object>>();
Map<String, Object> param = new HashMap<String, Object>();
System.out.println("請輸入您要查詢的女神姓名:");
String name = scanner.next();
param.put("name", "user_name");
param.put("rela", "=");
param.put("value", name);
params.add(param);
System.out.println("請輸入您要查詢的女神手機號:");
String mobile = scanner.next();
param = new HashMap<String, Object>();
param.put("name", "mobile");
param.put("rela", "=");
param.put("value", mobile);
params.add(param);
List<Goddess> list = null;
try {
list = action.query(params);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (OPERATION_SEARCH.equals(prenious)) {
step++;
} else if (OPERATION_ADD.equals(in.toUpperCase())
|| OPERATION_ADD.substring(0, 1).equals(in.toUpperCase())
|| OPERATION_ADD.equals(prenious)) {
prenious = OPERATION_ADD;
if (1 == step) {
System.out.println("請輸入女神的 【姓名】");
} else if (2 == step) {
goddess.setUser_name(in);
System.out.println("請輸入女神的 【年齡】");
} else if (3 == step) {
goddess.setAge(Integer.valueOf(in));
System.out.println("請輸入女神的【生日】 ;格式:yyyy-MM-dd");
} else if (4 == step) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Date birthday = null;
try {
birthday = sf.parse(in);
goddess.setBirthday(birthday);
System.out.println("請輸入女神的【郵箱】");
} catch (ParseException e) {
e.printStackTrace();
System.out.println("您輸入的格式有誤,請重新輸入!");
step = 3;
}
} else if (5 == step) {
goddess.setEmail(in);
System.out.println("請輸入女神的【手機號】");
} else if (6 == step) {
goddess.setMobile(in);
try {
action.add(goddess);
System.out.println("添加女神成功!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("添加女神失??!");
}
}
if (OPERATION_ADD.equals(prenious)) {
step++;
}
} else if (OPERATION_DELETE.equals(in.toUpperCase())
|| OPERATION_DELETE.substring(0, 1)
.equals(in.toUpperCase())) {
System.out.println("請輸入您要刪除的女神ID:");
Integer id = scanner.nextInt();
try {
action.del(id);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
查看全部 -
mybatis 和 hibernate 是orm映射工具
查看全部 -
jdbc的基本概念
查看全部 -
util date 和 sq date 互轉
查看全部 -
刪除行:ctrl + d
查看全部 -
class.forName()查看全部
-
execute操作執行更改數據庫的操作,executequery執行查詢操作并返回結果集;PreparedStatement預處理sql語句,并最后一起執行。
查看全部 -
MVC三層架構
查看全部 -
MVC三層架構
查看全部 -
MVC流程
查看全部
舉報