Query TimeOut Hints not working in Eclipse Link 2.6 when used with MSSQL Server DB
Tried with below options.
1.Adding hints to the Query Itself
Query query = em.createNamedQuery(AlertCategoryType.FIND_ACTIVE_TYPES);
query.setParameter("isInactive", Boolean.FALSE);
query.setHint(QueryHints.JDBC_TIMEOUT, "1");
Added Eclipse link hints to Named query
#NamedQuery(name = "AlertCategoryType.findByIsInactive", query = "SELECT a FROM AlertCategoryType a", hints={#QueryHint(name="eclipselink.jdbc.timeout", value="50")})
Added JPA hints to Named query
#NamedQuery(name = "AlertCategoryType.findByIsInactive", query = "SELECT a FROM AlertCategoryType a", hints={#QueryHint(name="eclipselink.jdbc.timeout", value="50")})
Tried adding property in persistence.xml
None of the above hints worked. Is there anything else missing out?
Please suggest any work around to work query time out when using any persistent provider with MSSQL server DB.
Thanks,
Vittal
If none of the above works with MS SQL Server try with javax.persistence.query.timeout. Keep in mind that neither a persistence provider nor database is obliged to support it.
As specified in JPA 2.0 Specification, chapter 3.8.9. Query Hints:
Portable applications should not rely on this hint. Depending on the
persistence provider and database in use, the hint may or may not be
observed.
If you are not tied to JPA 2.0 you can try with pure JDBC instead as it seems to be supported:
Is setQueryTimeout for JDBC driver 2.0 on CallableStatement supported?
MSDN > JDBC Driver API Reference > setQueryTimeout Method (SQLServerStatement)
Sample JDBC Driver Applications > Connection URL Sample
Related
I have a question I was hoping to get some feedback on being that it is my first time doing something like this.
I am building an intranet site and need to display a SQL view from SQL Server. I've done some research online and I've seen some people say use PHP to connect to the DB, then HTML to build a table... but those scenarios have been for MySQL or Access databases, not SQL Server.
My question is: what is the best way to to go about connecting and displaying a SQL Server view to an HTML 5 page? (I'm mainly just asking for some suggestions on where to start, any good documentation to look at, etc. not looking for someone to code it for me or anything like that)
First of all, you do not want to connect to the database directly from client side code, direct database queries should always be done on the server side.
I'd recommend using PHP because it's fairly simple, lightweight and widely supported.
You can query SQL Server with PHP, although you may need to download and install the PHP PDO drivers from Microsoft in order to do this. (Google 'sql server php pdo driver' and you'll be able to find them for your particular platform)
Alternatively you may be able to use an ODBC driver instead, although I haven't tried that personally.
In PHP you can use PDO to open a connection to your database, select from the view into an associative array using something like the following:
$pdo_object = new PDO($dsn, $user, $password);
$statement = $pdo_object->prepare("SELECT column1, column2 FROM view1");
$statement->execute();
$data = $statement->fetchAll(PDO::FETCH_ASSOC);
From here you can iterate over this data to render a table or pass it into javascript and have that populate a data grid.
I have strange effects when retrieving columns of type DATE from SQLServer2008 using the Microsoft JDBC-Driver version 3.0 when running under the official Oracle JDK 1.7.0. Host OS is Windows Server 2003.
All Date columns are retrieved as two days in the past with respect to the value actually stored in the column.
I cooked up a minimal code example the test this out (Test table and data):
CREATE TABLE Java7DateTest (
dateColumn DATE
);
INSERT INTO Java7DateTest VALUES('2011-10-10');
Code:
public class Java7SQLDateTest {
public static void main(final String[] argv) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection = DriverManager.getConnection(
"jdbc:sqlserver://192.168.0.1:1433;databaseName=dbNameHere",
"user", "password");
PreparedStatement statement = connection.prepareStatement("SELECT * FROM Java7DateTest");
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
final java.sql.Date date = resultSet.getDate("dateColumn");
final String str = resultSet.getString("dateColumn");
System.out.println(date + " (raw: " + str + ")");
}
resultSet.close();
statement.close();
connection.close();
} catch (final Throwable t) {
throw new RuntimeException(t.getMessage(), t);
}
}
}
Running this code on above configuration prints: "2011-10-08 (raw: 2011-10-08)".
Under JRE 1.6.0_27 it prints: "2011-10-10 (raw: 2011-10-10)"
I could not find anything that seems to relate to my problem with google, so I'm assuming that its either something stupid I overlooked or nobody is using Java7 yet.
Can anybody confirm this problem? What are my alternatives if I still want to use Java7?
Edit: The problem occurs even when running with -Xint, so its not caused by Hotspot bugs.
Edit2: Old drivers (Microsoft 1.28) work properly with JDK1.7.0 (we were using that driver until maybe two years ago, I think).
jTDS also works perfectly fine with the example. I am considering switching to jTDS, but I am reluctant to do so because I have not the faintest idea what the effects on our productive environment may be. Ideally it should just work, but that what I believed when I switched my dev box to Java7, too.
There is one pretty fat database in the production environment, that is too big to create a copy of, for testing (or rather our server has so little disk left). So setting up a test environment for that one app is not straigthforward, I would have to stitch up a shrinked database for that.
Edit3: jTDS has its own set of catches attached. I found a behavioral difference that breaks one of our applications. ResultSet.getObject() returns different object types for SmallInt columns depending on driver (Short vs Integer). Also jTDS does not implement JDBC4 Connection interface, Connect.isValid() is not supported.
Edit4: I noticed last week that MSSQL-JDBC 3.0 refuses to connect to any DB after I updated to JDK1.6.0_29. jTDS it is then... we switched the productive server yesterday (I fixed tow places where the application was relying on peculiarities of the driver), and so far we had have no problems.
Thank you for your feedback. The Microsoft JDBC Driver for SQL Server does not yet support JRE 1.7.
We are aware of the getDate issue between our JDBC driver & JRE 1.7 and we are looking into publishing a hotfix to enable customers to move forward with non-production testing of our driver with JRE 1.7.
We will publish a link to the hotfix on our blog once available.
http://blogs.msdn.com/b/jdbcteam/
The hotfix is now available. http://blogs.msdn.com/b/jdbcteam/archive/2012/01/20/hotfix-available-for-date-issue-when-using-jre-1-7.aspx
Our blog also contains information on the known issues with JRE 1.6u29 & 1.6u30.
Shamitha Reddy
Program Manager - Microsoft JDBC Driver for SQL Server
I don't quite have an answer for you. But, I've recreated your situation as you described. It is the same with the jdbc driver v3.101 and v3.202 and v4.ctp3 when run under jdk1.7. However, the v2 driver from MS gives your expected answer both under jdk1.6 and jdk1.7. If you need a quick fix and can move to an older jdbc driver, that may work for you.
Other thoughts are on how the MS jdbc driver handles dates and conversion of Date objects between SQL Server and the jvm. Since the storage of the date is without a time zone, the interpretation of the Date object by the driver is based on the default time zone for the machine running the jdbc driver. For instance, if you store a smalldate of '2011-10-11 12:00' and retrieve it from a machine with the default time zone set to GMT-7 then the resulting UTC time of the Date object would be '2011-10-11 19:00'. It could be that there is some change in jdk1.7 that impacts this conversion process in the driver resulting in a wild offset. You might experiment with the ResultSet.getDate(column, Calendar) method to see if a Calendar with a specific time zone gets you the result you want or helps make sense of why you are seeing the strange offset in the conversion.
I don't have a SQL Server setup, but I can't reproduce your problem with PostgreSQL 9.0 and MySQL 5.1 on Windows 7 x64 with JDK 1.7.0. So JDK 1.7.0 can be excluded from being suspect. I have the impression that the SQL Server JDBC driver is to blame here. I'd suggest to use the jTDS JDBC driver instead. It has always been praised for its better performance and stability as opposed to the MS-provided SQL Server JDBC driver.
Information and download link for the hotpatch from Microsoft Support can be found here:
http://support.microsoft.com/kb/2652061
I was experiencing the same issue, where the date would be off by two days, and this hotpatch fixed it.
This is also an issue in OpenJDK 1.6.0_20. However, the mssql driver works fine with Suns JRE 1.6.0_16.
Firstly, my cconfig is:
Language: ColdFusion 10(and installed update 11)
DB is MS SQL Server 2012
Using the jtds jdbc(tried versions 1.2.6, 1.2.8 and 1.3.0)
I'm currently having a problem running queries where I use cfqueryparam with a cfsqltype of cf_sql_nvarchar. The problem is the page just hangs. If I look at the application log of ColdFusion, I see the error of:
"net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setNString(ILjava/lang/String;)V The specific sequence of files included or processed is:" followed by the test filename.
I'm running a very basic select query on a nvarchar column, but the page doesn't load and that error is logged.
I know it's gotta be something to do with the jtds jdbc as if I connect through the regular sql driver it'll work perfectly.
So did anybody experience this before? If so, what was your resolution?
Thanks
I did a quick search and the results suggest jtds does not support setNString(). I checked the driver source for 1.3.1, and as mentioned in the comments here the method is not implemented:
"..while getNString is implemented the code just consists of // TODO
Auto-generated method stub and throw new AbstractMethodError();.."
So it sounds like you may need to use cf_sql_varchar, combined with the "String Format" setting, like in previous versions. Obviously, the other option is to use a different driver (one that does support setNString(), such as Adobe's driver or the MS SQL Server driver).
Try using cf_sql_varchar. cf_sql_nvarchar is not a valid option according to the Documentation and you should use cf_sql_varchar
We are in the process of upgrading WSO2 DSS from version 2.5.1 to 2.6.3. In version 2.5.1, we were able to execute stored procedures from our SQL Server 2005 database via services with no problems whatsoever. However, in this new version, that is not the case. When trying to execute a stored procedure in the TryIt window, an error is logged stating
ERROR {org.apache.axis2.transport.http.AxisServlet} - {org.apache.axis2.transport.http.AxisServlet} java.lang.AbstractMethodError
followed by a complete stack trace
If I change the query to a select statement, it works just fine.
Maybe there is some setting now that is needed prior to running stored procedures? Maybe it's another configuration issue? Hopefully someone can assist with this problem. I like the enhancements offered by this new version, but if we can't run stored procedures, it's not a viable option for us. Thanks in advance!
Jason
You have not actually posted the method they are complaining in the AbstractMethodError. But I'm guessing this is something to do with a JDBC driver which is not JDBC4 compliant. With Java 6, we are using JDBC4 features in WSO2 DSS, so you would have to upgrade to proper JDBC4 drivers, which is in MSSQL's case, would be the SQLJDBC4 driver. Hope this helps.
Cheers,
Anjana.
Is it possible to read the data stored in MS SQL server from R interface?
If it is I would be also thankful if anyone could show the way to do it.
Tried the RODBC package already?
http://cran.r-project.org/web/packages/RODBC/index.html
There's also the RJDBC package : http://www.rforge.net/RJDBC/
See also :
http://www.r-bloggers.com/connecting-to-sql-server-from-r-using-rjdbc/
I've applied RODBC function suggested by other users. LinkSQL Server RODBC Connection
library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL
Server};server=mysqlhost;database=mydbname;trusted_connection=true')
res <- sqlQuery(dbhandle, 'select * from information_schema.tables')
change two variables based on your Data table. 'server=mysqlhost;database=mydbname'
Niko, What operating system are you running? The answer to your question varies, depending on the platform you are using.
If you are using Windows (of any stripe), connecting to MSSQL Server via ODBC (RODBC) makes the most sense. When I connect to a MSSQL Server on Linux, I use JDBC as suggested by Joris. I would assume that JDBC is also the best solution for Macs, but I could very well be wrong.
There another option that seems to outperform RODBC and RJDBC
rsqlserver package written by agstudy.
Installation:
require(devtools)
install_github("rClr", 'jmp75')
install_github('rsqlserver', 'agstudy',args='--no-multiarch')
The latest library that allows you to connect to MSSQL databases is RSQLServer.
It can be found on GitHub and CRAN.
You can connect to SQL server using DBI package, which I think works better than RODBC. DBI is a database interface package for relational databases. for SQL I use it along with odbc package as in the example below.
Visit this page for full details: Database Queries with R
An example would be as follows
library(DBI)
library(odbc)
con <- dbConnect(odbc::odbc(), .connection_string = "driver={SQL Server}; server= ServerName; database=DatabaseName; trusted_conncetion=true"))
dbGetQuery(con,'Select * from Table')
library("RODBC")
dbhandle <- odbcDriverConnect('driver={SQL Server};server=;database=;trusted_connection=true')
currTableSQL<-paste("SELECT *
FROM ",sep="")
currTableDF<-sqlQuery(dbhandle,currTableSQL)