日期:2014-05-18  浏览次数:20730 次

jsp连接数据库问题~~~快疯了!!有人来帮帮我啊~~~
我在做一个一个页面连接两个数据库的测试
上面一段代码是用连接池连的,以前运行没有错误,我现在在下面又加上了一段在页面里连数据库的代码,但是出现了错误:
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   13   in   the   jsp   file:   /1.jsp
Generated   servlet   error:
Syntax   error,   insert   "AssignmentOperator   ArrayInitializer "   to   complete   ArrayInitializerAssignement

An   error   occurred   at   line:   13   in   the   jsp   file:   /1.jsp
Generated   servlet   error:
Syntax   error,   insert   "; "   to   complete   Statement

An   error   occurred   at   line:   13   in   the   jsp   file:   /1.jsp
Generated   servlet   error:
Syntax   error   on   token(s),   misplaced   construct(s)

An   error   occurred   at   line:   13   in   the   jsp   file:   /1.jsp
Generated   servlet   error:
Syntax   error,   insert   "; "   to   complete   Statement


第13行是 <%啊,怎么回事呢?我的jsp代码如下:请高手指点~~~

<%@page   contentType= "text/html;   charset=gb2312 "%>

<%@page   import   =   "javax.sql.DataSource "%>
<%@page   import   =   "javax.naming.InitialContext "%>
<%@page   import= "java.sql.* "%>
<html>
<head>
<title> 测试SqlServer2K数据库 </title>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
</head>
<body>
<h3> 测试SqlServer2K数据库 </h3>
<%
//InitialContext   ctx   =   new   InitialContext();  
//DataSource   ds   =   (DataSource)ctx.lookup( "java:/MSSQLDS ");//这里要和mysql-ds.xml中对应
//Connection   conn   =   ds.getConnection();
//Statement   stmt   =   conn.createStatement();  
//ResultSet   rs   =   stmt.executeQuery( "SELECT   *   FROM   tbb_map ");
//while   (   rs.next()   ){
//out.println(rs.getString( "mapname ")   +   " <br> ");
//}
//conn.close();
%>
<%
String   url= "jdbc:microsoft:sqlserver://222.128.7.111:1433;DatabaseName=test ";
String   driverName= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";//驱动
Try{
Class.forName(driverName);
Connection   con=DriverManager.getConnection(url,111,111);
Statement   s   =   con.createStatement();  
ResultSet   r   =   s.executeQuery( "SELECT   *   FROM   dm_lx ");
while   (   r.next()   ){
out.println(r.getString( "dmm ")   +   " <br> ");
}
}
Catch(Exception   e){}
%>


</body>
</html>

------解决方案--------------------
Try
Catch
大写了

------解决方案--------------------
楼主注意大小写
------解决方案