Tag: java

50894 ERROR reading: Incorrect syntax near the keyword 'user' when tries to select query to compare the username and password

public void login(String name,String password) throws SQLException{ try { Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”); } catch (ClassNotFoundException ex) { Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex); } java.sql.Connection conn = DriverManager.getConnection(“jdbc:sqlserver://;”+”user=looi963;password=1234;database=user”); PreparedStatement state=conn.prepareStatement(“Select username,password from user where username=? and password = ?”); state.setString(1,name); state.setString(2, password ); int count = state.executeUpdate(); if(count>0){ System.out.println(“Successful login”); } }

Cannot open port 1433 for Azure SQL database in Mac

I’m trying to access a Azure-hosted SQL database on my java application. I checked the port 1433 using nmap and it shows that it’s closed: Starting Nmap 7.12 ( https://nmap.org ) at 2016-09-02 09:44 PHT Nmap scan report for localhost ( Host is up (0.00014s latency). Other addresses for localhost (not scanned): ::1 PORT STATE […]

Jar file not running from MSSQL stored procedure?

Hi All I’m trying to run a jar a file from MSSQL stored procedure. But I’m getting the error “‘java‘ is not recognized as an internal or external command,” I’m using the following command from stored procedure EXEC master..xp_cmdshell ‘java -jar C:\admin\yyyyy\xxxx.jar’ I have installed JRE and also added it in environment variables. I’m able […]

How can I set bit column to null?

The following only wants a primitive boolean (true or false). psmt.setBoolean(5, boolean) ; //wants primitive What if I want to set the bit to null? Sql server = [bit] NULL

Hibernate: On SQL Server 2008 column was altered from datetime to datetime2. How I can update hibernate config to reflect this?

I have an application in which I created mappings of entities in Hibernate, so I could have access to some legacy tables on SQL Server 2005. Everything was working fine and as expected until the database was switched to a newer version of SQL Server – specifically, to SQL Server 2008. As the data were […]

Cannot connect to MSSQL due to Login-based server access validation failed with an infrastructure error

I have an application (web application) written in Java and database on MS SQL. Both, Tomcat (with application) and database server are on my localhost. I’m trying run an application but in Java logs I have: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Login failed for user ‘some-user’.) Caused by: java.sql.SQLException: Login failed for user ‘some-user’. In database […]

SQL Server 2008 datetime column JDBC insert problem

I have a table with a column that is a DATETIME in a SQL Server 2008 database. The dates that are being inserted are not timestamps in the sense that using NOW on insert would be acceptable. The date is generated a bit before the insert and I would like to preserve this value. Datetimes […]

Find SQL Servers using Java

This might be a basic question, but I tried googling it and couldn’t find an answer. I need to make a list of all the SQL Servers on a network. This is very easy to do using the .NET framework (System.Data.Sql.SqlDataSourceEnumerator), but is there also a relatively simple way to do this in java as […]

Which account is used when executing xp_cmdshell 'wmic … “java -jar …”'

I have a jar file that I want to run as a step in an SQL Job. However, the jar file has to run on machineA but the SQL job is schedule on serverA. To make this possible, in serverA’s SQL job, I use xp_cmdshell to issue a wmic command to the terminal. xp_cmdshell permits […]

Can not connect to ms sql server using windows authentication on remote system

I was trying to connect to ms sql server 2008 which is installed on a remote system.But it showing error.The following is the way i had tried import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; public class mssql { public static void main(String[] args) { try { Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”).newInstance(); Connection connection=DriverManager.getConnection(“jdbc:sqlserver://;databaseName=sales;integratedSecurity=true;”); if(!(connection==null)) […]

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