Tag: java

How to bind query parameters in hibernate if query is dynamic statement?

I am having a dynamic query as : DECLARE @LOERangeMin int =0 ; DECLARE @LOERangeMax int = 0; DECLARE @CycleStartStatus nvarchar(500) = :param1; DECLARE @CycleEndStatus nvarchar(500) = :param2; DECLARE @Team nvarchar(100) = NULL; DECLARE @ReportStartDate datetime = NULL; DECLARE @ReportEndDate datetime = GETDATE(); select min([Cycle Time]) AS AvgMinCycleTime,max([Cycle Time]) AS AvgMaxCycleTime,AVG([Cycle Time]) AS AvgCycleTime from […]

JDBC errors when running a T-SQL query that uses OPENQUERY to access a linked server

I’m trying to execute a SQL Server query using prepared statements: PreparedStatement pst = con.prepareStatement(“select * from openquery(SERVERNAME,” + “‘Select r.A , r.B, c.C from Y r” + “INNER JOIN X c” + “ON r.RNID = c.RNID ‘)” + “where c.C in ?”); pst.setString(1, data); ResultSet rs = pst.executeQuery(); I get this error message: com.microsoft.sqlserver.jdbc.SQLServerException: […]

how can i retrieve error messages to my java programmer from sqlserver

My primary keys are empid and date. what i want to do is ones a employee inserted a values to sql server and if he tries again to insert values to database in the same day, there primary key should be conflicted. so i want to display an error if he/she tries to do like […]

Customizing entity generation from datasource in IntelliJ IDEA

I want to generate my JPA-Entities from the database schema of an SQL Server 2012 using IntelliJ IDEA Ultimate 2016.2. I created a new data source and connected via JDBC to the server. Everything including the generation of the entities from database schema works. The problem is, that the ID fields in my database are […]

JTDS error: Native SSPI library not loaded

I’ve seen this question come up multiple times, but all the answers I’ve tried haven’t worked for me. The Connection string used to look like this url = “jdbc:jtds:sqlserver://server1/dbname;user=user;password=pswd”; //this one works fine url = “jdbc:jtds:sqlserver://server1;dbname;databaseName=dbname;integratedSecurity=true”; //doesn’t work but I am getting the exception. java.io.IOException: SSO Failed: Native SSPI library not loaded. Check the java.library.path […]

Connection Between Java App and Sql Server EXPR 2008 R2 Not Established

I’m newbie with SQL Server , i’m trying to connect my java Application to SQL Server, actually i get the JDBC jar file for MSSQL Driver from Microsoft Offical website then as showing in my Screenshot Here* the SQL Server Driver was imported well, but m problem i faced that i got this Exception while […]

Is there an alternative to UPDLOCK with NOWAIT that leaves the transaction committable?

Given the following: DB objects in SQL Server: create table t (c int); create table t2 (c int); create table t3 (c int); create table t4 (c int); create trigger tr on t after update as begin update t2 set c = c; end; create trigger tr2 on t2 after update as begin begin try […]

(Sum) query results in jtext

i want to create a function to show me the sum in Jtextfield .I dont know how to call the result any idea ? My jtextfieldname is sum_calc .Ty public void getSum() { Connection con =getConnection(); Statement st; PreparedStatement pst = null; ResultSet rs; try{ String qquery=” SELECT sum(Receipt.Sales_Quantity * Receipt.Pro_Price) AS TotalItemsOrdered FROM Receipt”; […]

Using Hibernate to connect to MS SQL Server

I’m trying to connect to an SQL Server database using Hibernate in Java. My hibernate.cfg.xml file looks like this: <hibernate-configuration>    <session-factory>   <property name = “hibernate.dialect”>org.hibernate.dialect.SQLServerDialect</property> <property name = “hibernate.connection.driver_class”>com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <property name = “hibernate.connection.url”>jdbc:sqlserver://*******.database.windows.net:1433;databaseName=*******;</property> <property name = “hibernate.connection.username”>*******@******</property> <property name = “hibernate.connection.password”>**********</property> <property name = “hibernate.show_sql”>true</property> </session-factory> </hibernate-configuration> After trying to run the app, I get […]

Hibernate Mapping Exception : Unknown Entity

I am mapping a simple POJO to a database table in SQL server using xml file mapping. I am getting Hibernate Mapping Exception : Unknown Entity These are my code files: Entry point class : public class Program { public static void main(String[] args) { System.out.println(“Helo World”); Session session = HibernateUtilities.getSessionFactory().openSession(); session.beginTransaction(); User user = […]

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