jsp串連mysql----------第一篇技術類文章

來源:互聯網
上載者:User

今天做作業連了一天的mysql。

最後我痛定思痛,決定從0開始學習jsp,省的又面臨不會的局面。

忙活了一晚上,終於把資料庫連接上了,不過,好傷心啊,我連個資料庫都這麼墨跡。。。

<%@ 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+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>    This is my JSP page. <br>    <%    String server="localhost";//MYSQL 伺服器的地址        String dbname="rowanhao";//MYSQL 資料庫的名字        String user="root";//MYSQL 資料庫的登入使用者名稱        String pass="zp930710";//MYSQL 資料庫的登入密碼        String port="3306";//SQL Server 服務器的連接埠號碼,預設為1433String 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 rs=stmt.executeQuery(sql);    while(rs.next())    {    out.println(rs.getString(1));    }    rs.close();    out.println("aaa");     %>  </body></html>

附帶:mysql中my.ini的配置

[mysqld]# set basedir to installation path, e.g., c:/mysql # 設定為MYSQL的安裝目錄 basedir=F:/datebase/mysql# set datadir to location of data directory, # e.g., c:/mysql/data or d:/mydata/data # 設定為MYSQL的資料目錄 datadir=F:/datebase/mysql/data[WinMySQLadmin]Server=F:/datebase/mysql/mysqld-nt.exe#user=root #password=root#以上是設定WinMySQLadmin的配置 #default-storage-engine=MyISAM


相關文章

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.