最简单的数据库连接实例

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.mysql.jdbc.*" %>
<%@ page import="java.sql.*" %>
<%
 String driverName = "com.mysql.jdbc.Driver";
 String userName = "root";
 String userPwd = "123456";
 String dbName = "netvii3d";
 String url = "jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPwd;

 try
 { 
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   java.sql.Connection conn = DriverManager.getConnection(url);
   java.sql.Statement statement = conn.createStatement();
   java.sql.ResultSet rs = statement.executeQuery("select * from video_info limit 20");
   while(rs.next())
   {
   out.println(rs.getString("name"));
   out.print("<br>");
   }
  
 }
 catch (SQLException ex)
 {
  out.print(ex.getMessage());
 }
%>

你可能感兴趣的:(数据库,String,jdbc,video,url,import)