📄 66.html
字号:
<STYLE type=text/css>
<!--
body,td { font-size:9pt;}
hr { color: #000000; height: 1px}
-->
</STYLE>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>论坛精华 >> Mysql >> 连接MySQL数据库</title>
</head>
<body >
<p><IMG SRC="../image/jsp001_middle_logo.gif" WIDTH="180" HEIGHT="60" BORDER=0 ALT=""></p>
<table width=100% bgcolor="#cccccc" align=center cellpadding="2" cellspacing="0" border=1 bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr bgcolor="#EFF8FF"><td>
<a href=http://www.jsp001.com/list_thread.php?int_attribute=4>论坛精华</a>
>> <a href=http://www.jsp001.com/list_thread.php?forumid=21&int_attribute=4>Mysql</a>
>> 连接MySQL数据库 [<a href=http://www.jsp001.com/forum/showthread.php?goto=newpost&threadid=66>查看别人的评论</a>]<br>
<hr><p>由 webmaster 发布于: 2001-01-20 16:43</p><p> </p><p>程序来源:iamafan@263.net<br><br><br>(编者按:由于是网上剪贴而来,html标记少了<...>,我没有补上)<br><br> <br><br>与数据库联接是做为WEB程序最基本的功能之一,JSP作为稳定的WEB PROGRAM,其数据库联接部分继承了JAVA的JDBC接口。使用起来与JDBC可以说是完全一致的。下面给出相应的例程,数据库服务器使用MYSQL,联接的驱动使用 mm.mysql.driver ,可以到 java.sun.com 的驱动程序库中查找相应的下载站点。 <br><br><br>使用JSP插入数据的例程 <br><br>html <br>head <br>titleThis is title/title <br>/head <br>body <br><%@ page import="java.sql.*" %> <br><% <br>//告诉编译器使用SQL包 <br>%> <br><% <br>try{ <br>Class.forName("org.gjt.mm.mysql.Driver"); <br>//加载 mm.mysql.driver <br>} catch (java.lang.ClassNotFoundException e) <br>//如果加载时出错,给出相应的错误信息 <br>{ <br>out.print("Class not found exception occur. Message is:"); <br>out.print(e.getMessage()); <br>} <br><br>try{ <br>Connection con; <br>Statement stmt; <br>ResultSet rs; <br>con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root;password="); <br>//创建数据库联接,这样的做法类似于M$的ASP中的创建数据库联接。 <br>stmt = con.createStatement(); <br>stmt.executeUpdate("INSERT INTO mytable (col1,col2) VALUES ('This is a test string',32)"); <br>//执行插入数据的操作 <br>rs = stmt.executeQuery("SELECT * FROM mytable"); <br>//把数据库中所有的数据读出来 <br>while (rs.next()) <br>{ <br>String s1 = rs.getString(1); <br>String s2 = rs.getString(2); <br>out.println("col1="+s1+"--col2="+s2+"br"); <br>//打印所显示的数据 <br>} <br>} catch (SQLException e) { <br>//如果SQL语句执行的过程中出错,则显示出相应的错误信息 <br>out.print("SQL Exception occur. Message is:"); <br>out.print(e.getMessage()); <br>} <br>%> <br><br>/body <br>/html<br><br></p></td>
</tr>
</table>
<p>
<CENTER><a href="http://www.jsp001.com/forum/newreply.php?action=newreply&threadid=66">点这里对该文章发表评论</a></CENTER>
<p>该文章总得分是 <font color=red>0</font> 分,你认为它对你有帮助吗?
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=66&intVote=4","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>非常多</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=66&intVote=2","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>有一些</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=66&intVote=1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>无帮助</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=66&intVote=-1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>是灌水</a>](<font color=red>0</font>) </p>
<script language="javascript" src="http://www.jsp001.com/include/read_thread_script.php?threadid=66"></script>
<p><CENTER>
Copyright © 2001 - 2009 JSP001.com . All Rights Reserved <P>
<IMG SRC="../image/jsp001_small_logo.gif" WIDTH="85" HEIGHT="30" BORDER=0 ALT="">
</CENTER></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -