⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 连接数据库.txt

📁 创建数据库的一点小知识,使用MYSQL+ jsp+ eclipse.
💻 TXT
字号:
linkMysql.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");}
   catch(Exception e) {out.print(e);}
   try { String uri="jdbc:mysql://localhost/Car";
   con=DriverManager.getConnection(uri,"root"," ");
   sql=con.createStatement();
   rs=sql.executeQuery("SELECT *FROM message");
   out.print("<tr>");
   out.print("<th width=100>"+"number");
   out.print("<th width=100>"+"name");
   out.print("<th width=50>"+"madeTime");
   out.print("<th width=50>"+"price");
   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("<td>"+rs.getDate(3)+"</td>");
        out.print("<td>"+rs.getFloat(4)+"</td>");
        out.print("</tr>");
       }
    out.print("</table>");
    con.close();
   }
   catch(SQLException e1){ out.print(e1);}
  %>
</BODY></HTML>



版本2
linkMysql.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");}
   catch(Exception e) {out.print(e);}
   try { String uri="jdbc:mysql://localhost/zhangjian";                    //zhangjian 为数据库名
   con=DriverManager.getConnection(uri,"root"," ");
   sql=con.createStatement();
   rs=sql.executeQuery("SELECT *FROM students");                          //students 为数据表名
   out.print("<tr>");
   out.print("<th width=100>"+"number");
   out.print("<th width=100>"+"name");
   out.print("<th width=50>"+"madeTime");
   out.print("<th width=50>"+"price");
   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("<td>"+rs.getDate(3)+"</td>");
        out.print("<td>"+rs.getFloat(4)+"</td>");
        out.print("</tr>");
       }
    out.print("</table>");
    con.close();
   }
   catch(SQLException e1){ out.print(e1);}
  %>
</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -