jsp连接mysql--------jdbc

<%@ 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 tableName = "video_info";
  
   String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPwd;
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   java.sql.Connection conn = DriverManager.getConnection(url);
  
   out.print("数据库连接生了!");
   out.print("<br>");
  
   java.sql.Statement statement = conn.createStatement();
   String sql = "select * from " + tableName +" limit 20";
   java.sql.ResultSet rs = statement.executeQuery(sql);
  
  
   while(rs.next())
   {
     out.println(rs.getString(2));
     out.println("<br>");
   }
  
    %>

 

你可能感兴趣的:(sql,jsp,String,jdbc,url,import)