Tag: java

EclipseLink ADD CONSTRAINT Exception

I would like to use create-or-extend-tables but eclipselink gives below error after tables were created. I am using Eclipselink 2.5.2 and db is MS Sql 2014 Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: ‘announcementCOMPANY_ID’ object already exists. Error Code: 2714 Call: ALTER TABLE announcement ADD CONSTRAINT announcementCOMPANY_ID FOREIGN KEY (COMPANY_ID) REFERENCES […]

JTDS driver – Cannot create PoolableConnectionFactory (I/O Error: DB server closed connection.)

I am attempting to connect to an SQL database hosted in Azure from a piece of software I’m using on an Azure VM, using the JTDS JDBC Driver. This isn’t software I have built/am developing, this is a third party program I am using to view my data. In the software I create data sources […]

Can't use DataSource after lookup

I am creating a JUnit to test a part of the application that uses Apache Shiro for authentication, for this I am creating a SQLServerConnectionPoolDataSource and binding it. The problem happens when I try to lookup the DataSource and get a connection, it fails the authentication of the user configured in the SQLServerConnectionPoolDataSource. After analyzing […]

java sql query error

I have this code: import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class DBConntest { public static void main(String[] args) { try { Connection conn = DriverManager.getConnection(“jdbc:mysql://127.0.0.1:3306/?user=root&useSSL=false”, “root”, “root”); System.out.println(“Connection succes!”); Statement stmt = conn.createStatement(); String query1 = “USE test; insert into dbtester(name,age,email) values (‘Aram’,18,’aram@gmail.com’);”; stmt.executeUpdate(query1); } catch (Exception e){ System.err.println(e);; } } } I use […]

Kerberos S4U extension for JDBC connections

Related with the question Using Kerberos S4U extensions (introduced in Java 8) to connect to database using JDBC I am in the same scenario right now. According to Microsoft documentation https://msdn.microsoft.com/en-us/library/cc246071.aspx: The Kerberos Security Support Provider (SSP) will first detect whether the forwarded-TGT delegation mechanism is available (by checking whether there is a forwarded TGT […]

Close unused JDBC PreparedStatement?

I have an application in which I am generating a batch of prepared statements. At the moment, if anything is added to the batch whatsoever, then I run executeBatch() and close() the statement. My question is, if the statement is prepared, but no batch is ever added, and the statement is never executed, should I […]

Cannot connect to SQL Server 2014 via java

Question has been updated (The DriverManager is no longer loaded manually and instead the getConnection() method is used): package guii; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.SQLException; /** * This program demonstrates how to establish database connection to Microsoft * SQL Server. * @author www.codejava.net * */ public class JdbcSQLServerConnection { public static void […]

Logs for SQL queries in Java using Eclipse

If I am using the below code query the database, where would I find the log file for the process? I am looking for what is being sent to the database. The query works from SQL Server Management Studio. The database is MS-SQL 2008. try{ Class.forName(“net.sourceforge.jtds.jdbc.Driver”); String userName = “dbuser”; String password = “dbpswd”; String […]

jsp update multiple rows from table

I’m writing a website using JSP and Servlet that require updating multiple record in a table in JSP into the database MSSQL. Suppose I have a table like this: Post.jsp <form method=”POST” action=”PostServlet?action=update”> <table border=”1″> <tr> <th>Post ID</th> <th>Title</th> <th>Date</th> <th>Status</th> </tr> <c:forEach var=”p” items=”${requestScope.list}”> <tr> <td>${p.id}</td> <td>${p.title}</td> <td>${p.date}</td> <td> <select name=”slStatus”> <option value=”approve” selected=”true”>Approve</option> […]

Kerberos ticket is not renewed on Wildfly

Ok, so I’m trying to connect to a MSSql Server from a Wildfly 9 sitting on an ubuntu, via Kerberos. The KDC is the Microsoft AD. I managed to get it working just fine, having a security-domain that looks like this: <login-module code=”org.jboss.security.negotiation.KerberosLoginModule” flag=”required” module=”org.jboss.security.negotiation”> <module-option name=”storeKey” value=”false”/> <module-option name=”useKeyTab” value=”true”/> <module-option name=”keyTab” value=”/opt/wildfly-9.0.2/standalone/configuration/krb5.keytab”/> <module-option […]

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