Connect with SQL Server 2005 Express with Java

I have problem with my project. It’s making me crazy – maybe you can help me.
I have a PC running SQL server 2005 Express and it works nicely.
In Eclipse I tested the following code to query the database:

String user= "sa";
String pass= "root";
Statement smt;
ResultSet rs = null;

try {
  Class.forName(""); // 2005 version
}catch (Exception e){}

try {
  Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=master",user,pass);
  smt = con.createStatement();
  smt.executeQuery("SELECT * from test");
  rs = smt.getResultSet();

  while ( {

} catch ( SQLException excepcionSql) {
  JOptionPane.showMessageDialog( null, excepcionSql.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );

And it works fine and runs the query. I downloaded the driver from Microsoft and added the sqljdbc4.jar to the class path.

  • TSQL Dynamic Query
  • Generate a XML and update it in a table in sql server without using cursor
  • TADOQuery Join tables - Insert \ Delete records from result
  • sql select query is not working in stored procedure
  • Why are dot-separated prefixes ignored in the column list for INSERT statements?
  • SQL: Find duplicated values associated with one ID
  • The project that must really access the database is another version of Eclipse (Eclipse SDK 3.2). It runs a web service which need to make queries to the database.
    I added the same jar to the class path and executing the same code, the line:


    throws this exception:

    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.banquito.Sucursales.HolaMundo.pruebaBD(
    at com.banquito.Sucursales.SucursalesSOAPImpl.getConfigPaciente(
    at com.banquito.Sucursales.SucursalesSOAPSkeleton.getConfigPaciente(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.axis.strategies.InvocationStrategy.visit(
    at org.apache.axis.SimpleChain.doVisiting(
    at org.apache.axis.SimpleChain.invoke(
    at org.apache.axis.handlers.soap.SOAPService.invoke(
    at org.apache.axis.server.AxisServer.invoke(
    at org.apache.axis.transport.http.AxisServlet.doPost(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.axis.transport.http.AxisServletBase.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.coyote.http11.Http11Processor.process(
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
    at org.apache.tomcat.util.threads.ThreadPool$
    at Source)

    Is seems Eclipse can’t resolve the export. Can somebody help me with that?

    3 Solutions collect form web for “Connect with SQL Server 2005 Express with Java”

    if you are using eclipse click configure build path, and add this jar into tha application and try again

    jar file seems to be missing, clean the project. If it still there try to create instance of or any other class present in that jar, you’ll get the answer.

    It looks like you are using some servlet container to run your app. So it better not to create connections to database directly from your app but create datasource in container and use it from your code.

    Then you’ll need to put jar with JDBC driver into lib folder of your container.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.