Installation and Testing System for MySQL and JDBC built in JSP Environment

Source: Internet
Author: User

Step 3 of JSP environment setup and MYSQL Installation

1) install MYSQL

 
 
  1. [root@linuxas Server]# rpm -vih perl-DBI-1.52-1.fc6.i386.rpm   
  2. warning: perl-DBI-1.52-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186  
  3. Preparing... ########################################### [100%]  
  4. 1:perl-DBI ########################################### [100%]  
  5. [root@linuxas Server]# rpm -vih mysql-5.0.22-2.1.i386.rpm   
  6. warning: mysql-5.0.22-2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186  
  7. Preparing... ########################################### [100%]  
  8. 1:mysql ########################################### [100%]  
  9. [root@linuxas Server]# rpm -vih perl-DBD-MySQL-3.0007-1.fc6.i386.rpm   
  10. warning: perl-DBD-MySQL-3.0007-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186  
  11. Preparing... ########################################### [100%]  
  12. 1:perl-DBD-MySQL ########################################### [100%]  
  13. [root@linuxas Server]# rpm -vih mysql-server-5.0.22-2.1.i386.rpm   
  14. warning: mysql-server-5.0.22-2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186  
  15. Preparing... ########################################### [100%]  
  16. 1:mysql-server ########################################### [100%] 

2) start the service

 
 
  1. [root@linuxas ~]# service mysqld start 

Initialize the MySQL database:

 
 
  1. Installing all prepared tables  
  2. Fill help tables  
  3. To start mysqld at boot time you have to copy support-files/mysql.server  
  4. to the right place for your system  
  5. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !  
  6. To do so, start the server, then issue the following commands:  
  7. /usr/bin/mysqladmin -u root password 'new-password'  
  8. /usr/bin/mysqladmin -u root -h linuxas password 'new-password'  
  9. See the manual for more instructions.  
  10. You can start the MySQL daemon with:  
  11. cd /usr ; /usr/bin/mysqld_safe &  
  12. You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:  
  13. cd sql-bench ; perl run-all-tests  
  14. Please report any problems with the /usr/bin/mysqlbug script!  
  15. The latest information about MySQL is available on the web at  
  16. http://www.mysql.com  
  17. Support MySQL by buying support/licenses at http://shop.mysql.com  

[OK]

Start MySQL: [OK]

Set the username and password for logging on to MySQL

 
 
  1. [root@linuxas ~]# mysqladmin -uroot password pwd@123 

Run mysql and grant the root user the remote access permission. For debugging

 
 
  1. use mysql   
  2. update user set host = '%' where user = 'root' and host < > 'localhost';   
  3. flush privileges;   
  4. quit  

Step 4 of JSP environment setup and JDBC Installation

1) download the installation process token from the official website.

2) install JDBC and configure tomcat

 
 
  1. [root@linuxas src]# tar -zxvf mysql-connector-java-5.1.7.tar.gz  
  2. [root@linuxas src]# cp mysql-connector-java-5.1.7/mysql-connector-java-5.1.7-bin.jar /tomcat/lib/  
  3. [root@linuxas src]# cp mysql-connector-java-5.1.7/mysql-connector-java-5.1.7-bin.jar /usr/local/src/jdk1.6.0_14/jre/lib/ 

Step 5: establish the JSP environment and test the system environment

1) Create a database and a table

 
 
  1. mysql> GRANT ALL PRIVILEGES ON *.* TO llk726@localhost IDENTIFIED BY 'pwd@123' WITH GRANT OPTION;  
  2. mysql> create database test;  
  3. mysql> use test;  
  4. mysql> create table testtable(id int not null auto_increment primary key, foo varchar(25), bar int);  
  5. mysql> insert into testtable values(null, 'hello', 12345); 

2) compile test. jsp

 
 
  1. [Root @ linuxas ROOT] # vi test. jsp
  2. <% @ PageContentType="Text/html; charset = gb2312" Language="Java"%> 
  3. <% @ PageImport="Java. SQL .*"%> 
  4. <%
  5. Class. forName ("com. mysql. jdbc. Driver"). newInstance ();
  6. StringUrl="Jdbc: mysql: // localhost/test? User = llk726 & password = pwd @ 123 & useUnicode = true & characterEncoding = utf8";
  7. ConnectionConn=DriverManager. GetConnection (url );
  8. StatementStmt=Conn. CreateStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDATABLE );
  9. StringSQL="Select * from testtable";
  10. %> 
  11. < Table Border=1> 
  12. < Tr> 
  13. < Td>Field 1</Td> 
  14. < Td>Field 2</Td> 
  15. < Td>Field 3</Td> 
  16. </Tr> 
  17. <%
  18. ResultSetRs=Stmt. ExecuteQuery (SQL );
  19. While (rs. next () {%> 
  20. < Tr> 
  21. < Td><% = Rs. getString ("ID") %> </Td> 
  22. < Td><% = Rs. getString ("FOO") %> </Td> 
  23. < Td><% = Rs. getString ("BAR") %> </Td> 
  24. </Tr> 
  25. <%} %> 
  26. </Table> 
  27. <% Rs. close ();
  28. Stmt. close ();
  29. Conn. close ();
  30. %> 

3) the test results are as follows:

The JSP running environment is successfully established. This article is from the "keyboard is life" blog.

  1. JDK installation and Tomcat configuration for JSP environment setup
  2. Discussion on how to implement the componentization of JSP image uploading
  3. Introduction to using jspsmart for file upload and download
  4. Use JSP pages to generate PDF reports
  5. Step for customizing JSP labels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.