本文目錄一覽:
JSP連接SQL資料庫出現的錯誤
可能是資料庫那錯了吧,你用的是2000的資料庫
不知道你的sp4補丁打了沒有,如果沒有就不能
用1433埠的。除非你用的2003的系統
這個是一個空指針異常,錯誤信息太少了,不怎麼好解決
連資料庫出錯(JSP連SQL)
估計是你的SQL Server 2000的jdbc驅動有問題,先重新下載jdbc驅動,然後加到classpath里,再試試。實在不行的話建議你換成ODBC試一下,應該就可以了。
具體方法是先設置數據源,然後
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:資料庫名", "sa",
"");
st=conn.createStatement();
jsp連接sql2005資料庫總是出錯!!
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 10 in the jsp file: /jsp/Adduser.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens
=============================================
運行你的頁面,發現提示如下:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 13 in the jsp file: /jsp_lpm/a.jsp
Resultset cannot be resolved to a type
10: %
11: Connection conn=null;
12: Statement st=null;
13: Resultset rs=null;
14: //載入驅動程序建立連接
15: try
16: {
An error occurred at line: 30 in the jsp file: /jsp_lpm/a.jsp
Syntax error on tokens, delete these tokens
27: try
28: {
29: st=conn.createStatement();
30: st.executeUpdate("insert into user values("zhangsan","000")");
31: out.println("添加數據成功!!");
32: }
33: catch(Exception e)
請先修改語法錯誤。
=============================================
我只知道「ResultSet」,不知道「Resultset」。我的Tomcat-6.x也因此報告編譯錯誤。替你修正後,第30行依然報語法錯誤。
你應當重新了解[字元串連接]和[引號使用]的注意事項——錯誤提示也是這樣說的。
=============================================
st.executeUpdate("insert into user values("zhangsan","000")");
——這一行顯然會出現語法錯誤,原因應該由你自己找。
另外,你最後給出的異常已經告訴你問題所在了:
java.lang.NullPointerException org.apache.jsp.jsp.Adduser_jsp._jspService(org.apache.jsp.jsp.Adduser_jsp:83)
jsp連接SQL2000資料庫出錯:解答好送高分
1.首先你的先裝SQL Server2000,如果是xp的話一般是裝開發版的,然後在打上補丁,加上三個驅動包,msbase.jar mssqlserver.jar msutil.jar 。我這裡還有一個集成的如果這三個還連不上的話。可以在本論壇發帖求助,我將會很快給予解答。代碼如下:
%@ page contentType="text/html;Charset=GB2312" %
%@ page import="java.sql.*" %
HTMLBODY bgcolor=cyan
% Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(ClassNotFoundException e)
{ out.print(e);
}
try{
String uri="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=aa"; !– 資料庫名 —
String user="sa"; !–SQL Server2000用戶名 —
String password="sa"; !–SQL Server2000密碼 —
con=DriverManager.getConnection(uri,user,password);
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM bb"); !– 表名 —
out.print("table border=2");
out.print("tr");
out.print("th width=100"+"姓名");
out.print("th width=100"+"密碼");
out.print("/tr");
while(rs.next())
{
out.print("tr");
out.print("td "+rs.getString(1)+"/td");
out.print("td "+rs.getString(2)+"/td");
out.print("/tr");
}
out.print("/table");
con.close();
}
catch(SQLException e)
{ out.print(e);
}
%
/BODY/HTML
我的SQL Server2000用戶名為sa,密碼也為sa,如果你的不是請改過來,資料庫名 aa
表名為bb,不是的也改過來,表裡兩個任意欄位.如果不能運行,
有什麼問題可以到這上問 jsp論壇
;topicSubId=3
轉載:
JSP無法連接SQL資料庫
檢查一下jar包是否引用,
檢查資料庫服務是否開啟
如果是MS
SQL2000,檢查是否打了SP4補丁
使用查詢分析器登錄,看是否能查詢
如果上面都沒問題,就換一下jar包吧.或者連接方式也可以換一下試試
jsp連接sql資料庫出現問題!
地球人都知道是空指針異常啦,可能的原因是用來返回連接資料庫得到的結果集為null(可能是SQL語句編寫錯誤)當然不一定是資料庫連接相關對象為空。老兄,你仔細看一下代碼,出現空指針異常一般是一個值為null的對象被操作,舉個簡單的例子如:String
str
=
null;
boolean
equ
=
str.equals("str");就會出現空指針異常
你可以通過手動修改代碼來調試,(接上面的例子)如:
String
str
=
null;
boolean
equ;
if(str
==
null){
System.out.println("對象str為空");
return;
}else{
equ
=
str.equals("str");
}
這裡System.out.println("對象str為空");語句可以理解為日誌信息,告訴你是哪個對象為null;
這樣你就可以解決問題了
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/271888.html