连接数据库,本人是初学者,望大家给予帮助,在线等待 ( 积分: 50 )

  • 主题发起人 主题发起人 都当主席谁种地
  • 开始时间 开始时间

都当主席谁种地

Unregistered / Unconfirmed
GUEST, unregistred user!
我的odbc数据源名称是jsp,我在执行时有一个错误说:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 5 in the jsp file: /mycon.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:/Tomcat 5.0/work/Catalina/localhost/_/org/apache/jsp/mycon_jsp.java:62: not a statement
con.close;
^
1 error

程序清单如下:
<%@ page contentType=&quot;text/html;charset=GB2312&quot;%>
<%@ page import=&quot;java.sql.*&quot;%>
<HTML>
<BODY>
<%
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);
}
catch(ClassNotFoundException e){}
try {con=DriverManager.getConnection(&quot;jdbc:odbc:jsp&quot;,&quot;sa&quot;,&quot;&quot;);
sql=con.createStatement();
rs=sql.executeQuery(&quot;select a from test&quot;);
out.print(&quot;<Table Border>&quot;);
out.print(&quot;<TR>&quot;);
out.print(&quot;<TH width=100>&quot;+&quot;a&quot;);
out.print(&quot;</TR>&quot;);
while (rs.next())
{out.print(&quot;<TR>&quot;);
out.print(&quot;<TD>&quot;+rs.getString(1)+&quot;</TD>&quot;);
out.print(&quot;</TR>&quot;);
}
out.print(&quot;</Table>&quot;);
con.close;
}
catch (SQLException e1){}
%>
</BODY>
</HTML>
 
我的odbc数据源名称是jsp,我在执行时有一个错误说:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 5 in the jsp file: /mycon.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:/Tomcat 5.0/work/Catalina/localhost/_/org/apache/jsp/mycon_jsp.java:62: not a statement
con.close;
^
1 error

程序清单如下:
<%@ page contentType=&quot;text/html;charset=GB2312&quot;%>
<%@ page import=&quot;java.sql.*&quot;%>
<HTML>
<BODY>
<%
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);
}
catch(ClassNotFoundException e){}
try {con=DriverManager.getConnection(&quot;jdbc:odbc:jsp&quot;,&quot;sa&quot;,&quot;&quot;);
sql=con.createStatement();
rs=sql.executeQuery(&quot;select a from test&quot;);
out.print(&quot;<Table Border>&quot;);
out.print(&quot;<TR>&quot;);
out.print(&quot;<TH width=100>&quot;+&quot;a&quot;);
out.print(&quot;</TR>&quot;);
while (rs.next())
{out.print(&quot;<TR>&quot;);
out.print(&quot;<TD>&quot;+rs.getString(1)+&quot;</TD>&quot;);
out.print(&quot;</TR>&quot;);
}
out.print(&quot;</Table>&quot;);
con.close;
}
catch (SQLException e1){}
%>
</BODY>
</HTML>
 
为什么什么内容都没有
 
为什么什么内容都没有
 
运行结果:捕捉到异常,输出“有异常”,可我不知有什么异样,请大家帮忙看看
<%@ page contentType=&quot;text/html;charset=GB2312&quot;%>
<%@ page import=&quot;java.sql.*&quot;%>
<HTML>
<BODY>
<%
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);
}
catch(ClassNotFoundException e){}
try {con=DriverManager.getConnection(&quot;jdbc:odbc:jsp&quot;,&quot;sa&quot;,&quot;&quot;);
sql=con.createStatement();
rs=sql.executeQuery(&quot;select * from test where a='1' &quot;);
out.print(&quot;无异常&quot;);
out.print(&quot;<Table Border>&quot;);
out.print(&quot;<TR>&quot;);
out.print(&quot;<TH width=100>&quot;+&quot;a&quot;);
out.print(&quot;</TR>&quot;);
while (rs.next())
{out.print(&quot;<TR>&quot;);
out.print(&quot;<TD>&quot;+rs.getString(1)+&quot;</TD>&quot;);
out.print(&quot;</TR>&quot;);
}
out.print(&quot;</Table>&quot;);
con.close();
}
catch (SQLException e1){out.print(&quot;有异常&quot;);}
%>
</BODY>
</HTML>
 
不用了,我自己以解决了问题
 
后退
顶部