Tag: java

Can I amend the executed SQL before execution using an AspectJ pointcut

I’m trying to add a specific piece of SQL to all SQL executed in a system using AspectJ. I’ve not used AspectJ before but I believe what I need to do is create a pointcut on call(PreparedStatement Connection.prepareStatement(String)) and provide the advice before(Connection con, String sql): call(PreparedStatement Connection.prepareStatement(String)) && target(con) && args(sql) { sql = […]

JDBC | SQL Server connection error

I’m trying to generate some reports to my system using Jasper reports. I’m suing basic JDBC connection method to establish a connection to my SQL Server 2000. Here is my code snippet: public static Connection getConnection()throws ClassNotFoundException, SQLException { Class.forName(driver); Connection conn = DriverManager.getConnection(connectString, user, password); return conn; } But I’m getting a SQL incorrect […]

method takes too long

I wrote a method that gathers data from an Oracle server, formats and encrypts the data then inserts it into a MS SQL server. The method moves about 60000 records and takes a bit long and is a little sloppy. Can anyone see places to clean it up and make it faster? 2 of the […]

criteria query ORDER BY yields error. Is this an SQL-SERVER limitation? How could I order by correctly on a complicated criteria query?

I have the following criteria query: String cat = “H”; Criteria criteria = currentSession().createCriteria(this.getPersistentClass()). add(Restrictions.ne(“category”, cat)). createAlias(“employees”, “emp”). createAlias(“emp.company”, “company”); Disjunction disjunction = Restrictions.disjunction(); for(Region r: regions){ disjunction.add(Restrictions.eq(“company.region”, r)); } criteria.add(disjunction); if(status != null) { criteria.add(Restrictions.eq(“status”, status)); } if (period != null) { criteria.add(Restrictions.eq(“period”, period)); } criteria.setProjection(Projections.groupProperty(“id”)) //this line was added to try to “fix” […]

SQL and Java return different dates?

I am using sqljdbc4.jar to connect SQL Server from my java application. I have a date field in my table. It works normally when I check from Sql Server Management Studio. But in java, every date is 2 day missing. For example; my date : 2012-01-10 date in java : 2012-01-08 PreparedStatement stmt = conn.prepareStatement(“SELECT […]

Java : save data from UTF-8 file into Sql Server 2008

I failed to save data with accents from utf8 file into my SQL Server 2008 table – SQL collation = SQL_Latin1_General_CP1_CI_AS – (when I do a System.out.print of my insert statement : the accents are OK). Here’s the steps I’m doing : 1) Convert file to String : File f = new File(file); byte[] buffer […]

Incorrect Syntax near 'Contribution'

I developed a Java application with MS SQL Server 2008 as database. I am using the JDBC drivers available on Microsoft’s website. It was working fine till now. But as the load increased, a lot of SQLServerException appeared. The query is INSERT INTO ANSWERS VALUES (‘pd’,’GK002′,’A’,’B’,”,”,’Yes’,’QUIZ012′) The exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ‘Contribution’. at […]

how to get current date time in sql server?

I want to pass sys date to my procedure. Below is my code snippet DateFormat dateFormat = new SimpleDateFormat(“mm/dd/yyyy”); Date date = new Date(); String insertquery=”{ call sp_process_job (?,?,?) }”; cs = con.prepareCall(insertquery.toString()); cs.setString(1,id); cs.setString(2,host); cs.setDate(19,(java.sql.Date) date); cs.execute(); con.commit(); My stored Procedure create procedure sp_process_job (@request_id varchar(25),@host varchar(20),@created_on varchar(25)) as begin set dateformat mdy SELECT […]

Parse Apple plist with TSQL

I’m working with a SQL Server 2008 database that stores Apple plists in a column. I’m looking for a quick and dirty way to extract some of that information. I know SQL Server can do XML parsing. Since a plist isn’t true XML, is there anything out there that can help me query/manipulate the data? […]

Using SQLXMLBulkload via Java

Is it possible to use the SQLXMLBulkload component of SQL Server using Java? I am using SQL Server 2005 database for my Java EE application. If not then is there any similar API for Java?

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