How to make Java work with SQL Server?

前端 未结 9 1402
别那么骄傲
别那么骄傲 2020-12-13 06:23

I know this is a basic question, but I can\'t seem to find an answer and I apologize, if this question is way too stupid, but here we go:

I am supposed to work with

相关标签:
9条回答
  • 2020-12-13 06:58

    I had the same problem with a client of my company, the problem was that the driver sqljdbc4.jar, tries a convertion of character between the database and the driver. Each time that it did a request to the database, now you can imagine 650 connections concurrently, this did my sistem very very slow, for avoid this situation i add at the String of connection the following parameter:

     SendStringParametersAsUnicode=false, then te connection must be something like url="jdbc:sqlserver://IP:PORT;DatabaseName=DBNAME;SendStringParametersAsUnicode=false"
    

    After that, the system is very very fast, as the users are very happy with the change, i hope my input be of same.

    0 讨论(0)
  • 2020-12-13 07:02

    The driver you are using is the MS SQL server 2008 driver (sqljdbc4.jar). As stated in the MSDN page it requires Java 6+ to work.

    http://msdn.microsoft.com/en-us/library/ms378526.aspx

    sqljdbc4.jar class library requires a Java Runtime Environment (JRE) of version 6.0 or later.

    I'd suggest using the 2005 driver which I beleive is in (sqljdbc.jar) or as Oxbow_Lakes says try the jTDS driver (http://jtds.sourceforge.net/).

    0 讨论(0)
  • 2020-12-13 07:03

    For anyone still googling this, go to \blackboard\config\tomcat\conf and in wrapper.conf put an extra line in wrapper.java.classpath pointing to the sqljdbc4.jar and then update the wrapper.conf.bb as well

    Then restart the blackboard services and tomcat and it should work

    It won't work by simply setting your java classpath, you have to set it up in the blackboard config files to point to your jar file with the jdbc library

    0 讨论(0)
  • 2020-12-13 07:05

    Do not put both the old sqljdbc.jar and the new sqljdbc4.jar in your classpath - this will make it (more or less) unpredictable which classes are being used, if both of those JARs contain classes with the same qualified names.

    You said you put sqljdbc4.jar in your classpath - did you remove the old sqljdbc.jar from the classpath? You said "it didn't work", what does that mean exactly? Are you sure you don't still have the old JAR in your classpath somewhere (maybe not explicitly)?

    0 讨论(0)
  • 2020-12-13 07:09

    If you are use sqljdbc4.jar, use the following code

    ResultSet objResultSet = objPreparedStatement.getResultSet();
    if (objResultSet == null) {
      boolean bResult = false;
      while (!bResult){
        if (objPreparedStatement.getMoreResults()){
          objResultSet = objPreparedStatement.getResultSet();
          bResult = true;
        }
      } 
    }
    objCachedRowSet = new CachedRowSetImpl();
    objCachedRowSet.populate(objResultSet);
    if (CommonUtility.isValidObject(objResultSet)) objResultSet.close();
    objResultSet = null;
    
    0 讨论(0)
  • 2020-12-13 07:10

    Maybe a little late, but using different drivers altogether is overkill for a case of user error:

    db.dbConnect("jdbc:sqlserver://localhost:1433/muff", "user", "pw" );
    

    should be either one of these:

    db.dbConnect("jdbc:sqlserver://localhost\muff", "user", "pw" );
    

    (using named pipe) or:

    db.dbConnect("jdbc:sqlserver://localhost:1433", "user", "pw" );
    

    using port number directly; you can leave out 1433 because it's the default port, leaving:

    db.dbConnect("jdbc:sqlserver://localhost", "user", "pw" );
    
    0 讨论(0)
提交回复
热议问题