search
HomeDatabaseMysql TutorialJSP连接mysql数据库(1)_MySQL

JSP连接mysql数据库(1)_MySQL

Jun 01, 2016 pm 02:06 PM
mysqluseCanOrderInstalldatabaseconnect

一. 软件下载
  Mysql
  下载版本:4.1.11
  http://dev.mysql.com/downloads/mysql/4.1.html

  JDBC驱动
  下载版本:3.1.8
  http://dev.mysql.com/downloads/connector/j/3.1.html

  Mysql界面插件:mysql-front
  下载版本镜像:HongKong(下回来安装就是中文版了)
  http://www.mysqlfront.de/download.html

二. 软件安装
  1.安装mysql
  请参阅资料版区相关文章

  http://info.mysql.cn/install/2006/0208/81.html

  2.JDBC驱动:mysql-connector-java-3.1.8
  这只是一个压缩包,并不需要安装,只要将其解压,我么使用的是文件夹mysql-connector-java-3.1.8里的文件:mysql-connector-java-3.1.8-bin.jar.

  3. Mysql界面插件:mysql-front
  这是一个安装程序,按照提示安装就可以了.

三. 环境配置
   首先,我要说明的是我现在tomcat的安装路径是: D:\Program Files\Java\Tomcat;JDK的安装路径是:D:\Program Files\Java\j2sdk。

  在这里,需要配置环境变量的是JDBC驱动.在配置前先要把刚才说到的mysql-connector-java-3.1.8-bin.jar本地硬盘某处(我放的地方:D:\Program Files\Java\mysqlforjdbc),然后根据你放的地方,配置classpath,我的配置是这样的:

  D:\Program files\Java\j2sdk\lib\tools.jar;

  D:\Program Files\Java\j2sdk\lib\mysql-connector-java-3.1.8-bin-g.jar;

  D:\Program Files\Java\mysqlforjdbc\mysql-connector-java-3.1.8-bin.jar

  配置这个的目的是让你的java应用程序找到连接mysql的驱动.

  配置完环境变量后还有很重要一步就是为JSP连接数据库配置驱动,这个其实很简单,就是把mysql-connector-java-3.1.8- bin.jar拷到某些文件夹里就行了,我在网上看了很多资料问了很多人,各种说法都有,我综合了一下,为了保险,我都全做了,呵呵,反正就是拷一个 400K的文件而已,现列出要把mysql-connector-java-3.1.8-bin.jar拷进去的文件夹,如下:
  D:\Program Files\Java\Tomcat\common\lib
  D:\Program Files\Java\Tomcat\shared\lib

四. 数据库的使用

  Mysql安装完毕以后,还有一些要注意的地方(参考):

  http://info.mysql.cn/install/2006/0208/82.html

  就象在文章提到的,mysql安装好后最重要一样就是要看数据库有没有作为系统服务启动了,所以在大家进行数据库操作前,应要看看,在操作系统的开始->运行->输入services.msc,确定你在安装时你设置的关于mysql的那个服务已经启动,这样你在操作数据库时不会报连接不上的错误.

  上面提到了一个较方便的mysql界面插件,但是这个界面是我在已经开始使用mysql后才找到的,刚开始我是在dos下用命令行进行操作的.虽然那个界面也可以进行建库啊,设定权限等操作,但是,我觉得懂得在使用命令行也是一个很重要的技能,所以我先从命令行开始说,怎样简单使用mysql.到后面会谈及mysql-front的使用.

  现在我想在mysql里建一个数据库shujuku,以及在数据库里建一个表biao.具体的命令如下(假设mysql我是刚安装好的)

  1. 进入dos状态(记住命令行的要运行在mysql的安装目录下的bin目录的)

  2. 连接mysql
  输入:mysql –h localhost –u root –p
  输入在安装时已设好的密码,就近入了mysql的命令编辑界面了。

  3. 使用mysql的基本命令(在mysql命令行编辑每输入完命令后最后一定要有分号,不然会报错)
  显示数据库:show databases;
  使用数据库:use 数据库名;

  4.建库
  命令:create database shujuku;

  5.为数据库设置权限(用户和密码)
  命令:grant all privileges on shujuku.* to test@localhost identified by “123456”;
  当你执行完这个命令以后,只要你再以用户名:test,密码:123456登录时你就只可以对shujuku这个数据库操作,这样避开使用root,对数据库的安全有很大帮助.

  6.建表
  命令:create table biao(id int(8) primary key,name varchar(10));

  剩下来的与标准sqsl命令基本上是一样的,具体操作略
  值得一提的是,你在命令行上输入"?",就会有mysql命令的简单帮助,如下:

  呵呵,那样,我们还可以知道退出,就是"exit",呵呵!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool