免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
JSP通過JDBC驅(qū)動MySQL數(shù)據(jù)庫方法
關(guān)于MySQL數(shù)據(jù)庫安裝請參考下面這篇文章:
http://blog.csdn.net/javamxj/archive/2005/01/13/251861.aspx

關(guān)于eclipse的使用,請參考我的blog其他文章。
http://blog.csdn.net/rickhunterchen/archive/2005/09/11/477382.aspx
http://blog.csdn.net/rickhunterchen/archive/2005/09/11/477386.aspx


1、首先在MySQL數(shù)據(jù)庫中建立books數(shù)據(jù)庫,再建book表。
然后插入數(shù)據(jù)。SQL語言如下:

create database books;

use books;
create table book(bookId varchar(50),bookName varchar(50),publisher varchar(100),price float,constraint pk_book primary key(bookId))TYPE=MyISAM,default character set gbk;(加粗字體是我在建表時(shí)就對默認(rèn)字體進(jìn)行的固定,因?yàn)槲覜]有使用javamxj的在windows中加my.ini文件的做法)
          
insert into book values(‘1001‘,‘Tomcat與Java Web開發(fā)技術(shù)詳解‘,‘電子工業(yè)出版社‘,45.00);
insert into book values(‘1002‘,‘精通Struts:基于MVC的Java Web設(shè)計(jì)與開發(fā)‘,‘電子工業(yè)出版社‘,49.00);
insert into book values(‘1003‘,‘精通Hibernater:Java對象持久化技術(shù)詳解‘,‘電子工業(yè)出版社‘,59.00);
insert into book values(‘1004‘,‘精通EJB‘,‘電子工業(yè)出版社‘,59.00);
insert into book values(‘1005‘,‘J2EE應(yīng)用與BEA Weblogic Server‘,‘電子工業(yè)出版社‘,56.00);

2、接著在eclipse3.1中建立一個(gè)名為MySQL的項(xiàng)目:

3、建議mysql.jsp文件。輸入以下代碼:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<html>
<body>
以下是從MySQL數(shù)據(jù)庫讀取的數(shù)據(jù):<hr>
<table border=1>
<tr><td>ID</td><td>書名</td><td>出版社</td><td>價(jià)格</td></tr>

<%
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/BookDB?useUnicode=true&characterEncoding=GBK","t14cwf","cwf");
   Statement stmt=con.createStatement();
    ResultSet rst=stmt.executeQuery("select * from book");
    while(rst.next())
    {
        out.println("<tr>");
        out.println("<td>"+rst.getString("bookId")+"</td>");
        out.println("<td>"+rst.getString("bookName")+"</td>");
        out.println("<td>"+rst.getString("publisher")+"</td>");
        out.println("<td>"+rst.getFloat("price")+"</td>");
        out.println("</tr>");
    }
    //關(guān)閉連接、釋放資源
    rst.close();
    stmt.close();
    con.close();
    %>
</table>
</body>
</html>

4、將mysql-connector-java-3.1.10-bin.jar文件復(fù)制到tomcat\common\lib

5、可以在eclipse中運(yùn)行jsp文件了。

6、運(yùn)行結(jié)果:



很多人連接不上數(shù)據(jù)庫最多的原因還在于wem.xml文件問題。
一下是lomboz自動生成的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>
    MySQL</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
在應(yīng)用程序中配Proxool連接池
java連接mysql數(shù)據(jù)庫詳細(xì)步驟解析
tomcat連接池的配置與使用(mysql)
java jsp tomcat6 mysql 連接池配置
JSP連接mysql數(shù)據(jù)庫攻略
Java源碼閱讀的真實(shí)體會
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服