将Eclipse连接到SQL Server时出错

时间:2014-06-10 09:20:15

标签: java eclipse jsp

这是语法错误

Jun 10, 2014 5:15:51 PM org.apache.catalina.core.AprLifecycleListener
 init
 INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on
 the java.library.path: C:\Program Files   
 (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program
 Files (x86)/Java/jre7/bin/client;C:/Program Files
 (x86)/Java/jre7/bin;C:/Program Files
 (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\NVIDIA
 Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS
 Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\AMD
 APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program
 Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files
 (x86)\Common Files\Microsoft Shared\Windows
 Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
 Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ATI
 Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R)
 Management Engine Components\DAL;C:\Program Files\Intel\Intel(R)
 Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R)
 Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R)
 Management Engine Components\IPT;C:\Program Files\Microsoft\Web
 Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET
 Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows
 Performance Toolkit\;C:\Program Files\Microsoft SQL
 Server\110\Tools\Binn\;C:\Program Files (x86)\Microchip\MPLAB C32
 Suite\bin;C:\Program Files\Java\jdk1.7.0_25\bin;C:\Program Files
 (x86)\Java\jdk1.7.0_03\bin;c:\Program Files (x86)\Microsoft SQL
 Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files
 (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft
 SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL
 Server\100\DTS\Binn\;c:\Program Files\Microsoft SQL
 Server\100\DTS\Binn\;C:\Program Files
 (x86)\Google\google_appengine\;C:\Users\Patrick\Desktop\2013-2014 2nd
 Sem Files\Eclipsee\eclipse;;. Jun 10, 2014 5:15:51 PM
 org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING:
 [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting
 property 'source' to 'org.eclipse.jst.jee.server:B2B' did not find a
 matching property. Jun 10, 2014 5:15:51 PM
 org.apache.coyote.AbstractProtocol init INFO: Initializing
 ProtocolHandler ["http-bio-8080"] Jun 10, 2014 5:15:51 PM
 org.apache.coyote.AbstractProtocol init INFO: Initializing
 ProtocolHandler ["ajp-bio-8009"] Jun 10, 2014 5:15:51 PM
 org.apache.catalina.startup.Catalina load INFO: Initialization
 processed in 544 ms Jun 10, 2014 5:15:51 PM
 org.apache.catalina.core.StandardService startInternal INFO: Starting
 service Catalina Jun 10, 2014 5:15:51 PM
 org.apache.catalina.core.StandardEngine startInternal INFO: Starting
 Servlet Engine: Apache Tomcat/7.0.42 Jun 10, 2014 5:15:52 PM
 org.apache.coyote.AbstractProtocol start INFO: Starting
 ProtocolHandler ["http-bio-8080"] Jun 10, 2014 5:15:52 PM
 org.apache.coyote.AbstractProtocol start INFO: Starting
 ProtocolHandler ["ajp-bio-8009"] Jun 10, 2014 5:15:52 PM
 org.apache.catalina.startup.Catalina start INFO: Server startup in 374
 ms com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax
 near '`'.

这是我的代码

package b2b.fishermall;

public class ConnectionString extends SqlStringCommands
{   
    public String getDriver()
    {       
       return "com.microsoft.sqlserver.jdbc.SQLServerDriver";   
    }       
    public String getURL()
    {       
        return "jdbc:sqlserver://localhost:1433;databaseName=B2B;integratedSecurity=true;";
    } 
    public String getUsername()
    {       
        return "";  
    }       
    public String getDbPassword()
    {       
        return "";  
    } 
}

1 个答案:

答案 0 :(得分:2)

你的代码不好。不要这样做。

当三个静态最终字符串完美地完成时,这就是很多代码。更好的是,你应该把这些东西外化。

数据库没有用户名或密码?哦,我的。

如果您正在使用Tomcat,那么正确的做法是使用JNDI连接池。 Tomcat有detailed docs向您展示如何。

让我再猜一下:你正在编写带有scriptlet的JSP。另一个“不做”。如果必须使用JSP,请学习JSTL。

我无法从堆栈跟踪中分辨出任何东西。还有别的吗?