234234234

<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%> 
<% @page import="java.sql.*" %>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> <head>               
<title>JSP读取数据库</title>
</head> <body> 
<table border="1" align="center">
 <tr>    
<th>公司代码</th>    <th>公司名称</th>    <th>连接人</th>    <th>网站</th> 
</tr> 
<%    String driverClass="com.mysql.jdbc.Driver"; 
String url="jdbc:mysql://10.0.20.108:3306/test";//之前数据库名simple    
String user="root";//MySQ帐号    
String password="";//MYSQL密码    
Connection conn;    
try {     Class.forName(driverClass).newInstance();     
conn=DriverManager.getConnection(url,user,password);     
Statement stmt=conn.createStatement();    
String sql="SELECT * FROM code where id = 107";//表名book     
ResultSet rs=stmt.executeQuery(sql);     
while(rs.next()){ 

/* String strUserName = rs.getString(1);
    String strPassWord = rs.getString(2);
    String strEmail = rs.getString(3);
    System.out.println(strUserName+"\t"+strPassWord+"\t"+strEmail+"\t"); */
    
%>


<tr>    
<td><%=rs.getString("id")%></td>        
<td><%=rs.getString("name")%></td>    
<td><%=rs.getString("link")%></td>    
<td><%=rs.getString("web")%></td> </tr> 
</table>
<%     }    }catch(Exception ex){      
ex.printStackTrace();    
} %> 


</body> 
</html>

你可能感兴趣的:(234234234)