Jsp connection to mysql ---------- first technical article _ MySQL

Source: Internet
Author: User
Jsp connects to mysql ---------- The first technical article that connects to mysql for one day today.

Finally, I decided to start learning jsp from scratch, saving me the trouble.

After a full night of work, I finally connected the database. However, it's so sad that I even have a database...

<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ page import =" data. database "%> <% @ page import =" java. SQL. * "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %>My JSP 'index. jsp 'starting page
 
 
 
 
 
 This is my JSP page.
<% String server = "localhost"; // MYSQL server address String dbname = "rowanhao"; // MYSQL database name String user = "root "; // MYSQL database logon username String pass = "zp930710"; // MYSQL database logon password String port = "3306"; // SQL Server port number, the default value is 1433 String url = "jdbc: mysql: //" + server + ":" + port + "/" + dbname + "? User = "+ user +" & password = "+ pass +" & useUnicode = true & characterEncoding = GB2312 "; Class. forName ("org. gjt. mm. mysql. driver "). newInstance (); Connection conn = DriverManager. getConnection (url); Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDATABLE); String SQL = "select * from student"; ResultSet rs1_stmt.exe cuteQuery (SQL); while (rs. next () {out. println (rs. getString (1);} rs. close (); out. println ("aaa"); %>

WITH: my. ini configuration in mysql

[Mysqld] # set basedir to installation path, e.g ., c:/mysql # set to the installation directory basedir = F:/datebase/MYSQL # set datadir to location of data directory, # e.g ., c:/mysql/data or d:/mydata/data # set it to the MYSQL data directory datadir = F:/datebase/mysql/data [WinMySQLadmin] Server = F: /datebase/mysql/mysqld-nt.exe # user = root # password = root # The above is the configuration of WinMySQLadmin # default-storage-engine = MyISAM

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.