问题描述
packagetest;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassTest{privatestaticConnectionconn=null;privatestaticStatementstmt=null;publicstaticvoidmain(String[]args)throwsSQLException,ClassNotFoundException{Testtest=newTest();booleanbool=test.checkUser("ttt");System.out.println(bool);}publicbooleancheckUser(Stringusername)throwsClassNotFoundException,SQLException{Stringsql="select*fromuser1whereusername='"+username+"'";Stringurl="jdbc:odbc:Driver={MicrosoftAccessDriver(*.mdb)};DBQ=d:\test.MDB";Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn=DriverManager.getConnection(url);ResultSetrs2=null;stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);try{rs2=stmt.executeQuery(sql);if(rs2.next()){conn.close();returntrue;}}catch(SQLExceptione){e.printStackTrace();returnfalse;}try{conn.close();}catch(SQLExceptione){e.printStackTrace();}returnfalse;}}这段哪里出错执行时返回500
解决方案
解决方案二:
把錯誤訊息貼出來吧
解决方案三:
试写的一个AJAX这是前面的代码<%@pagelanguage="java"import="java.util.*"pageEncoding="gbk"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title></title><scriptlanguage="javascript">functiongetBackInfo(){if(document.getElementById('username').value==""){tag=0;document.getElementById("disCheckResult").innerHTML='ID不能为空';}else{url='checkUser.jsp?username='+document.getElementById("username").value;//定义网址参if(window.XMLHttpRequest){xmlhttp_request=newXMLHttpRequest();}elseif(window.ActiveXObject){xmlhttp_request=newActiveXObject("Microsoft.XMLHTTP");}else{return;}//xmlhttp_request=getXMLRequester();//调用创建XMLHttpRequest的函数xmlhttp_request.onreadystatechange=doContents;//调用doContents函数xmlhttp_request.open('GET',url,true);xmlhttp_request.send(null);}}functiondoContents(){if(xmlhttp_request.readyState==4){alert(xmlhttp_request.readyState+'用来添加提示信息');//收到完整的服务器响应if(xmlhttp_request.status==200){alert(xmlhttp_request.responseText);document.getElementById("disCheckResult").innerHTML=xmlhttp_request.responseText;}else{alert(xmlhttp_request.status+'失败!');}}}</script></head><body><formaction=""name="form"method="get"><table><tr><td><inputtype=textid="username"onblur="getBackInfo();"></td><td><ddid="disCheckResult"></dd></td></tr></table></form></body></html><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><%@pagecontentType="text/html;charset=GBK"%><%@pageimport="test.Test"%><html><head><metahttp-equiv="Content-Type"content="text/html;charset=GBK"/><title>checkUser</title></head><body><%Stringusername=request.getParameter("username");Testtest=newTest();if(test.checkUser(username))out.println("用户名已经存在!");//这个信息就是发送到前台去显示的信息,即服务器返回的信息elseout.println("可以继续!");%></body></html>数据库在D根目录下名字为test就一张表user1就一个字段username万分感谢。。
解决方案四:
sun.jdbc.odbc.JdbcOdbcConnection@f99ff5java.sql.SQLException:[Microsoft][ODBCMicrosoftAccessDriver]参数不足,期待是1。atsun.jdbc.odbc.JdbcOdbc.createSQLException(UnknownSource)atsun.jdbc.odbc.JdbcOdbc.standardError(UnknownSource)atsun.jdbc.odbc.JdbcOdbc.SQLExecDirect(UnknownSource)atsun.jdbc.odbc.JdbcOdbcStatement.execute(UnknownSource)atsun.jdbc.odbc.JdbcOdbcStatement.executeQuery(UnknownSource)attest.Test.checkUser(Test.java:32)attest.Test.main(Test.java:19)falseStringurl="jdbc:odbc:Driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:\test.MDB";
解决方案五:
Connectioncon=DriverManager.getConnection("jdbc:odbc:数据源名字","数据源用户名","数据源密码");自己百度下就知道了么
解决方案六:
该回复于2010-11-09 16:03:33被版主删除
解决方案七:
new以个driver就可以了,还用百度么
解决方案八:
conn=DriverManager.getConnection(url);这句话少参数。应该是:conn=DriverManager.getConnection(url,username,password);
解决方案:
引用楼主hehaiyang7133862的回复:
Stringurl="jdbc:odbc:Driver={MicrosoftAccessDriver(*.mdb)};DBQ=d:\test.MDB";
没什么,就多了两个空格,应该是这样的Stringurl="jdbc:odbc:Driver={MicrosoftAccessDriver(*.mdb)};DBQ=d:\test.MDB";