随笔-208  评论-469  文章-30  trackbacks-0

数据库链接的建立
首先应当加载JAVA 2 SDK 中提供的JDBC-ODBC驱动程序,链接ODBC数据库 ,才能进行数据库链接的建立操作。

conn.jsp


<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
     <%  Connection con;
          Statement sql;
          ResultSet rs;
          try{
              Class.forName("com.mysql.jdbc.Driver").newInstance();
          }
          catch(ClassNotFoundException e){
          e.getMessage();
          }
          try{
              con=DriverManager.getConnection("jdbc:mysql://localhost/zk1011111_db?user=zk1011111&password=t1y1v1n1&useUnicode=true&characterEncoding=gb2312"); 
              sql=con.createStatement();
              rs=sql.executeQuery("SELECT name,email FROM t_test");
              out.print("<Table Border>");
              out.print("<tr>");
              out.print("<TH width=100>"+"姓名");
              out.print("<TH width=100>"+"邮件");
              out.print("</tr>");
              while(rs.next()){ 
                  out.print("<TR>");
                  out.print("<TD>"+rs.getString(1)+"</TD>");
                  out.print("<TD>"+rs.getString(2)+"</TD>");
                  out.print("</TR>");
              }
             out.print("</Table>");
             con.close();
         }
         catch(Exception e){
             e.getMessage();
         }
     %>
</body>
</html>

]]>

posted on 2007-01-13 21:32 EricWong 阅读(159) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: