是这样的,JSP源程序如下
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%
Connection con = null; try { Class.forName("org.gjt.mm.mysql.Driver").newInstance();
out.println("JDBC driver loaded");
}
catch (ClassNotFoundException cnfe) {
out.print("ClassNotFoundException: Could not locate driver");
}
con = DriverManager.getConnection("jdbc:mysql://localhost/my?root,aa");
out.println("Database connection established");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String upd = "CREATE TABLE aa(Author_ID INTEGER NOT NULL PRIMARY KEY,Author_Name CHAR(50));";
stmt.executeUpdate(upd);
out.println("Table - aa created");
String b="zhang";
String sql2="insert into aa(Author_ID,Author_Name) values('"+2+"','"+b+"')";
stmt.executeUpdate(sql2);
String sql3="select * from aa ";
ResultSet rs=stmt.executeQuery(sql3);rs.next();
%>
Author_ID <%=rs.getString("Author_ID")%>
Author_Name<%=rs.getString("Author_Name")%>可是,我看过mysql库中,表aa建立了且记录(2,b)也加入,就是不能查询
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%
Connection con = null; try { Class.forName("org.gjt.mm.mysql.Driver").newInstance();
out.println("JDBC driver loaded");
}
catch (ClassNotFoundException cnfe) {
out.print("ClassNotFoundException: Could not locate driver");
}
con = DriverManager.getConnection("jdbc:mysql://localhost/my?root,aa");
out.println("Database connection established");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String upd = "CREATE TABLE aa(Author_ID INTEGER NOT NULL PRIMARY KEY,Author_Name CHAR(50));";
stmt.executeUpdate(upd);
out.println("Table - aa created");
String b="zhang";
String sql2="insert into aa(Author_ID,Author_Name) values('"+2+"','"+b+"')";
stmt.executeUpdate(sql2);
String sql3="select * from aa ";
ResultSet rs=stmt.executeQuery(sql3);rs.next();
%>
Author_ID <%=rs.getString("Author_ID")%>
Author_Name<%=rs.getString("Author_Name")%>可是,我看过mysql库中,表aa建立了且记录(2,b)也加入,就是不能查询
org.apache.jasper.JasperException: Column 'Author_ID' not found.