JDBC数据源

<%@ page language="java" import="java.sql.*,com.mchange.v2.c3p0.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

  </head>
  
  <body>
    <%
    	String sql="select * from student where id=?";
    	
    	
    	ComboPooledDataSource dataSource= new ComboPooledDataSource();
    	
    	Connection conn=dataSource.getConnection();
    	PreparedStatement pstmt = conn.prepareStatement(sql);
    	pstmt.setInt(1,5);
    	ResultSet rs=pstmt.executeQuery();
    	
    	if(rs.next())
    	{
    		int mid=rs.getInt(1);
    		String name=rs.getString(2);
    		int age=rs.getInt(3);
    		double scores=rs.getDouble(4);
    	
    		out.println(mid);
    		out.println(name);
    		out.println(age);
    		out.println(scores);
    	}
    	pstmt.close();
    	conn.close();
    	
     %>
  </body>
</html>

  

猜你喜欢

转载自www.cnblogs.com/lijunzone/p/9258592.html