最近刚开始学JSP,在编写一个数据库的字符串调出到一个数组中的时候,总是报有异常,希望各位高手帮忙解决一下,在此谢谢各位啦。下面是源程序:
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
This is my JSP page. <br>
<%
String number=null;
String[] Number=null;
int Line=0;
String url = "jdbc:mysql://localhost:3306/oa";
String userName = "root";
String password = "123";
try{
//String str;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,userName,password);
Statement sql = con.createStatement();
String strSql = "SELECT * FROM check_user;";
ResultSet rs = sql.executeQuery(strSql);
int i = 0;
while(rs.next()){
number = rs.getString(2);
Number[i]="number"; //系统总是在这报错,也没说明什么错误
i++;
}
Line = i;
rs.close();
con.close();//断开连接
}catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.print(Number);
%>
</body>
</html>
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
This is my JSP page. <br>
<%
String number=null;
String[] Number=null;
int Line=0;
String url = "jdbc:mysql://localhost:3306/oa";
String userName = "root";
String password = "123";
try{
//String str;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,userName,password);
Statement sql = con.createStatement();
String strSql = "SELECT * FROM check_user;";
ResultSet rs = sql.executeQuery(strSql);
int i = 0;
while(rs.next()){
number = rs.getString(2);
Number[i]="number"; //系统总是在这报错,也没说明什么错误
i++;
}
Line = i;
rs.close();
con.close();//断开连接
}catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.print(Number);
%>
</body>
</html>
谢谢