知识是一点一滴地积累的,MySQL数据库今天算是对我开启了一个新纪元。
今天我想讲的有两点:
1、MySQL 创建数据库、创建表、插入字段代码。
当然也可以通过可视化编程工具MyManagerLiteSetup.exe,但是今天是用的时候,却不能创建表中的数据。
# SQL Manager 2005 for MySQL 3.7.5.1
# —————————————
# Host : localhost
# Port : 3306
# Database : wirelessorder_db
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES gbk */;
SET FOREIGN_KEY_CHECKS=0;
CREATE DATABASE `wirelessorder_db`
USE `wirelessorder_db`;
#
# Structure for the `menutbl` table :
#
CREATE TABLE `menutbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`typeID` int(11) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`price` int(11) DEFAULT NULL,
`pic` varchar(100) DEFAULT NULL,
`remark` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
INSERT INTO `menutbl` (id,typeID, name, price, pic, remark) VALUES (null,1,'水煮鱼',20,'test','test'),
(null,2,'凉拌西红柿',10,'tets','test');
#
# Structure for the `menutypetbl` table :
#
CREATE TABLE `menutypetbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
#
# Structure for the `orderdetailtbl` table :
#
CREATE TABLE `orderdetailtbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`orderId` int(11) DEFAULT NULL,
`menuId` int(11) DEFAULT NULL,
`num` int(11) DEFAULT NULL,
`remark` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
#
# Structure for the `ordertbl` table :
#
CREATE TABLE `ordertbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`orderTime` varchar(30) DEFAULT NULL,
`userID` int(11) DEFAULT NULL,
`tableId` int(11) DEFAULT NULL,
`personNum` int(11) DEFAULT NULL,
`isPay` int(11) DEFAULT NULL,
`remark` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
#
# Structure for the `tabletbl` table :
#
CREATE TABLE `tabletbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`num` int(11) DEFAULT NULL,
`flag` int(11) DEFAULT NULL,
`description` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
#
# Structure for the `usertbl` table :
#
CREATE TABLE `usertbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL,
`gender` varchar(20) DEFAULT NULL,
`permission` int(11) DEFAULT NULL,
`remark` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
#
# Data for the `menutbl` table (LIMIT 0,500)
#
COMMIT;
#
# Data for the `menutypetbl` table (LIMIT 0,500)
#
INSERT INTO `menutypetbl` (`id`, `name`) VALUES
(1,'热菜'),
(2,'凉菜');
COMMIT;
#
# Data for the `orderdetailtbl` table (LIMIT 0,500)
#
INSERT INTO `orderdetailtbl` (`id`, `orderId`, `menuId`, `num`, `remark`) VALUES
(1,1,2,1,'ok'),
(2,1,1,2,'ok');
COMMIT;
#
# Data for the `ordertbl` table (LIMIT 0,500)
#
INSERT INTO `ordertbl` (`id`, `orderTime`, `userID`, `tableId`, `personNum`, `isPay`, `remark`) VALUES
(1,'11:50:07 02:04',1,2,5,NULL,NULL),
(2,'11:13:07 04:04',1,3,2,NULL,NULL),
(3,'11:14:07 04:04',1,1,2,NULL,NULL);
COMMIT;
#
# Data for the `tabletbl` table (LIMIT 0,500)
#
INSERT INTO `tabletbl` (`id`, `num`, `flag`, `description`) VALUES
(1,1,1,'1'),
(2,2,1,'2'),
(3,3,1,'3'),
(4,4,0,'4'),
(5,5,0,'5');
COMMIT;
#
# Data for the `usertbl` table (LIMIT 0,500)
#
INSERT INTO `usertbl` (`id`, `account`, `password`, `name`, `gender`, `permission`, `remark`) VALUES
(1,'admin','123','tom','male',1,'test');
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2、在通过网络与远程或本地数据库交互时应该注意的问题。
android中访问网络经常会出现一些莫名奇妙的问题,目前归纳一下,本人觉得可能是
1) 没有在 AndroidManifest.xml 加Intent访问权限,一定得在AndroidManifest.xml文件加上网络访问权限!
即<uses-permission android:name="android.permission.INTERNET"/>
2) 数据库里面一定要有东西,表一定要设计内容!否则你想通过数据库来验证登录时就会出现空指针异常或者其他异常。因为你是要通过数据库来验证的,数据库里没有东西,怎么验证??
3) 遇到向MySql数据库插入数据时编译器会爆有问题,而代码本身没问题。这时候你就需要注意了。
a、可能是字符编码的问题-----utf8与gbk,这时去MySQL安装目录下找到my.ini文件,把其中的
default-character-set=utf8 改为default-character-set=gbk。
b、要是还不行的话,可能是SQL语句太长,把比较长的SQL语句的截成两行使用试试。
4) 测试网络连接时总是出现错误,原因可能有:
a、 服务器(如Tomcat服务器)一直开着,但是改了配置文件后没有重启服务!这就得注意了,你没有重启服务那么服务器中记录的是你原来的信息,所以必须得重启服务器。
b、URL的信息要对:url格式如下:http://主机号:端口号/目标路径?表达式1&表达式2&表达式http://192.168.40.11:8080/WirelessOrder_Server/servlet/LoginServlet?account=admin&password=123