Tag: java

Workaround for JDBC Limitation on Placeholders Fails for Update Statements

I am implementing a pattern to get around a JDBC limitation. For prepared statements, JDBC limits the number of placeholders to 2100. To get around this, I am using an xml string containing 2100+ values and parsing it on SQL Server’s side using a function tf_splitxml. I am doing this for ~4 Java methods that […]

Trying to connect to SQL Server 2008 Express database with SQL Server authentication always result in “Login failed for user '…'.”

I am using jTDS to connect a Liferay instance to an SQL Server 2008 Express server using the SQL Server authentication (instead of the Windows’ auth method). I have something like this in my portal-ext.properties: jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver jdbc.default.url=jdbc:jtds:sqlserver://127.0.0.1:1433/somedb jdbc.default.username=someuser jdbc.default.password=somepassword (For those that do not know Liferay, it is somewhat alike to call Class.forName(“net.sourceforge.jtds.jdbc.Driver”); con = […]

Spring JDBC for SQL Server – Using SQLXML datatypes yields SQLServerException: Implicit conversion from data type xml to nvarchar(max) is not allowed

I’m trying to make use of a SQL Server stored procedure that uses XML in/out parameters using a Spring SimpleJdbcCall as per this example from the Spring 3.2 documentation (http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/jdbc.html): public class JdbcActorDao implements ActorDao { private JdbcTemplate jdbcTemplate; private SimpleJdbcCall procReadActor; public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.procReadActor = new SimpleJdbcCall(dataSource) […]

Calling SQL server 2008 Stored Procedure from Java

I have created the following stored procedure in SQL server 2008 Create PROCEDURE countInfected @infected int out AS Select @infected = COUNT(*) from userInfo where userID NOT IN (Select userID from deletedInfo); My java Code is as follow CallableStatement infected = con.prepareCall(“exec countInfected()”); infected.registerOutParameter(1, java.sql.Types.INTEGER); infected.execute(); System.out.println(“Infected”+ infected.getInt(1)); but it generate the following error java.lang.NullPointerException […]

Hibernate:Populating specific columns while doing insert in to Database

For persisting data used hibernate with SQLServer. In system every table contains four column. 1. Created User 2. Created Date 3. Modified User 4. Modified Date From beginning system does not contain any mechanism for entering “modified User” and “modified Date” while insert and update operation. My Question. is there any way in hibernate to […]

can't get arabic letters from sqlserver using java

I’m trying to retrieve result from MS SQL Server using netbeans. the problem is when I retrieve Arabic words from the database I receive it as ????? . Any one can help ? and here is the code: Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection conn = DriverManager.getConnection(“jdbc:odbc:yasser”); System.out.println(“test”); Statement sta = conn.createStatement(); String Sql = “select * from mainn […]

How to write same value into 2 Databases?

I need to insert the same values into 2 different databases. What is the best approach in order to do this ? Can I somehow make this using some configurations tweaks, or creating code for each operation is the only way? I’m mainly using Java + MSSQL.

Java connection string for sqlserver for localdb

I have done Java application using Netbeans and Sqlserver 2012. So for developing the application i ran Sqlserver in particular port and used the below string for connecting. public static Connection connectDB(){ try { Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”); Connection conn = DriverManager.getConnection(“jdbc:sqlserver://localhost\\SQLEXPRESS:1433;databaseName=DB1;user=zubair;password=zubair1234″); //JOptionPane.showMessageDialog(null,”Connection established”); return conn; }catch (Exception ex){ JOptionPane.showMessageDialog(null,ex); return null; } } Now for delivering the […]

Java SQL JDBC Error – No suitable driver found error

I’m trying to get my head around Java and how it works with JDBC so I’ve set up a SQL 2012 Express server on my domain controller. I’ve successfully connected to it via a domain computer using another SQL 2012 instance but when using Java to pull a simply query down I get a ‘No […]

Testing the SQL Server driver existence

If I have to test for the driver, Is it the correct way of doing it: try { // Loading the Driver Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”); } catch(java.lang.ClassNotFoundException e) { return false; } I keep on getting an error on the line return false that boolean cannot be converted to integer. Please correct me if I am wrong. […]

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