MySQL数据库一般指MySQL,MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发。
mysql是目前网站以及APP应用上用得较多的一个开源的关系型数据库系统,可以对数据进行保存,分段化的数据保存,也可以对其数据进行检索,查询等功能的数据库。
默认的mysql数据库中存有一个库这个就是mysql的系统数据库,可以对其保存系统的数据包括mysql数据库的信息,数据库root账号,普通账号,以及数据库的名称,还有数据库的一些表还有一些数字型的数据类型结构都会有所保存。
mysql数据库的优点
(1)MySQL数据库是用C和C++语言编写的,并且使用了多种编辑器进行测试,以保证源码的可移植性。
(2)支持多个 *** 作系统例如:Windows、Linux、Mac OS等等。
(3)支持多线程,可以充分的利用CPU资源。
(4)为多种编程语言提供API,包括C语言、Java、PHP、Python语言等。
(5)MySQL优化了SQL算法,有效的提高了查询速度。
(6)MySQL内提供了用于管理,检查以及优化数据库 *** 作的管理工具。
(7)它能够作为一个单独的应用程序应用在客户端服务器网络环境中,也可以作为一个库嵌入到其他的软件中并提供多种语言支持。
数据库内容
java源代码 (代码实现的是查询成绩为 的人员信息 至于其他功能的 代码中有注释) 注意 在eclipse里运行程序的时候 要工程里插入jar包 否则运行异常! import java sql *import java io *class database_manage { public Connection conn = null public ResultSet rs = null private String DatabaseDriver = " mysql jdbc Driver" // DataSource 数据源名称DSN private String DatabaseConnStr = "jdbc:mysql://localhost: /people_manage?useUnicode=true&characterEncoding=utf " + " root root" public void setDatabaseDriver(String Driver) { this DatabaseDriver = Driver } public String getDatabaseDriver() { return (this DatabaseDriver) } public void setDatabaseConnStr(String ConnStr) { this DatabaseConnStr = ConnStr } public String getDatabaseConnStr() { return (this DatabaseConnStr) } public database_manage() {// 构造函数连接数据库 try { Class forName(DatabaseDriver)} catch (java lang ClassNotFoundException e) { System err println("加载驱动器有错误:" + e getMessage()) System out print("执行插入有错误:" + e getMessage())// 输出到客户端 } } public ResultSet query(String sql) {// 查询数据库 rs = nulltry { conn = DriverManager getConnection( "jdbc:mysql://localhost: /people_manage?useUnicode=true&characterEncoding=utf " "root" "root") Statement stmt = conn createStatement() rs = stmt executeQuery(sql)} catch (SQLException ex) { System err println("执行查询有错误:" + ex getMessage()) System out print("执行查询有错误:" + ex getMessage())// 输出到客户端 }return rs
} public int update_database(String sql) {// 更新或插入数据库 int num = try { conn = DriverManager getConnection( "jdbc:mysql://localhost: /people_manage?useUnicode=true&characterEncoding=utf " "root" "root") Statement stmt = conn createStatement() num = stmt executeUpdate(sql)} catch (SQLException ex) { System err println("执行插入有错误:" + ex getMessage()) System out print("执行插入有错误:" + ex getMessage())// 输出到客户端 } CloseDataBase()return num } public void CloseDataBase() {// 关闭数据库 try { conn close()} catch (Exception end) { System err println("执行关闭Connection对象有错误 " + end getMessage()) System out print("执行执行关闭Connection对象有错误 有错误:" + end getMessage())// 输出到客户端 } } } class people { private String uid private String name private String banji private int score public people() { } public people(String uid String name String banji) { this uid = uidthis name = namethis banji = banji } public people(String uid String name String banji int score) { this uid = uidthis name = namethis banji = banjithis score = score } public String getUid() { return uid } public void setUid(String uid) { this uid = uid } public String getName() { return name } public void setName(String name) { this name = name } public String getBanji() { return banji } public void setBanji(String banji) { this banji = banji } public int getScore() { return score } public void setScore(int score) { this score = score } } public class manage { private people[] people_array // 对象数组 public void add_people(String uid String name) { String sql = "insert people (uid name) values ( " + uid + " " + name + " )"// sql插入语句 // String sql = "insert people (uid name) values ( uid tom )" database_manage db_obj = new database_manage()db_obj update_database(sql) } public void update_people(String uid String name) { String sql = "update people set name= " + name + " where uid= " + uid + " "database_manage db_obj = new database_manage()db_obj update_database(sql) } public void delete_people(String uid) { String sql = "delete from people where uid= " + uid + " " database_manage db_obj = new database_manage() db_obj update_database(sql) } public people query_people(String uid) { database_manage db_obj = new database_manage()// String adminid=nullString uid_new name banjiuid_new = nullname = nullbanji = nullString sql_query = "select * from people where uid= " + uid + " " try { ResultSet rs = db_obj query(sql_query) if (rs next()) { uid_new = rs getString("uid")name = rs getString("name")banji = rs getString("banji") } } catch (Exception e) { e getMessage()} people new_people = new people(uid_new name banji)return new_people } public people[] query_people_byscore(int score) { database_manage db_obj = new database_manage()String uid_new name banjiuid_new = nullname = nullbanji = nullint score_new =String sql_query = "select * from people where score=" + score// sql查询语句
try {
ResultSet rs = db_obj query(sql_query)// 查询后 返回结果集
int num =
ResultSet rs_new = rs
while (rs_new next()) {// 统计结果集中学生个数
num++
}
// System out println(num)
people_array = new people[num]
int i =
rs beforeFirst()// 返回结果集的开始
while (rs next()) {
uid_new = rs getString("uid")
name = rs getString("name")
banji = rs getString("banji")
score_new = rs getInt("score")
people_array [i] = new people(uid_new name banji score_new)
i++
}
} catch (Exception e) {
e getMessage()
}
return people_array
}
public static void main(String args[]) {
/*
* people new_people=new people()
*
* manage mr=new manage()//mr add_people(" " "小明")插入一个学生的信息
*
* new_people=mr query_people(" ")//查询uid= 的学生信息 返回对象 System out
* println(""+new_people getName()+" "+new_people getBanji())
* mr update_people(" " "小王")更新一个学生的信息
*
* new_people=mr query_people(" ")//更新后查询
*
* System out println(""+new_people getName()+" "+new_people getBanji(
* ))
*/
manage mr = new manage()
// mr delete_people(" ")删除uid= 的学生信息
people[] people_array// 声明对象数组
people_array = mr query_people_byscore( )// 返回成绩为一百的学生类数组 后输出
int num =
num = people_array length
for (int i = i <numi++) {
System out println(people_array[i] getUid() + " "
+ people_array[i] getName() + " "
+ people_array[i] getBanji() + " "
+ people_array[i] getScore())
}
}
}
lishixinzhi/Article/program/Java/JSP/201311/20030
1、在MySQL数据库安装时选择过MySQL服务器随系统启动,但如果没有选择,也没关系,可以在可以在Windows服务管理器启动,具体在开始菜单搜索services.msc,
2、单击出现如下图窗口,下滑鼠标找到MySQL57:
3、右击后点击启动,MySQL57旁边状态列显示“已启动”字样,说明启动成功。如下图:
二、登录MySQL数据库
4、用系统命令行工具登录,点击开始菜单,找到附件,点击命令提示符。
5、在命令行中输入cd加空格然后粘贴bin路径:cdc:\ProgramFiles(x86)\MySQL\MySQLServer5.7\bin回车命令行定位到c:\ProgramFiles(x86)\MySQL\MySQLServer5.7\bin>,在后面输入mysql_hlocalhost_uroot_p(这些都是安装时设置好的)敲回车,
6、出现Enterpassword:在后面输入安装时设置的登录密码,按回车后出现WelcometotheMySQLmonitor.说明登陆成功。如下图:
7、用安装时配置好的命令行工具登录,在开始菜单,点击MySQL5.7CommandLineClient或下面搜索程序框中输入comm选择MySQL5.7CommandLineClient启动DOS命令窗口。如下图:
8、在窗口Enterpassword:处输入安装时设置的MySQL数据库客户端登陆密码,回车,如果出现WelcomtotheMySQLmonitor.等字眼表示登陆服务器成功,可以在闪烁光标处输入SQL可执行语言:如下图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)