I'm learning JDBC at the moment and I already know the difference between PreparedStatement and Statement. It is that PreparedStatement is precompiled and allows you to set parameters, but I was asked a question on a job interview about difference be
Could anyone provide some guidance on how to use Table Value Parameters (TVP) with SQL Server JDBC? I am using the 6.0 version of the SQL Server driver provided by Microsoft, and I have reviewed the official documentation as well as the more helpful
I am trying to execute an SQL statement through Java and write the results to a .csv file. I am using OJDBC.jar (v7) to connect to Oracle 11g DB and OPENCSV.jar (v3.8) for creating and writing into the excel. Table result is printing very well. I am
I am unable to execute 'delete' query in java. The query executes fine in command prompt. Following is the code. String deleteQuery = "delete from id_table where id ='1666'; int result = Connection.createStatement().executeUpdate(deleteQuery); I do n
I retrieved some data from MySQL using JDBC and I want to store all the data in a JSONArray and write it into a file. Can someone help me? I`m getting following error: "Exception in thread "main" org.json.JSONException: A JSONArray text mus
I have a singleton connector object that helps in connecting to a mysql database. public class Connector{ private Connector(){ } public static Connector getInstance(){ if(unique == null) unique = new Connector(); return unique; } public void connect(
I have been through these questions - choose a db connection pool , Is DB connection pooling all that important and java - DataSource for standalone application - no application server and those don't answer my curiosity. What I have is a standalone
In my Java EE application I implemented autentication/autorization via a JDBC Realm (first time I apply this solution). Following code does not have any problem on successful login, the problem is when I type wrong credentials: it logs in anyway and
My Java application needs to authenticate to Google cloud Mysql instance with SSL client authentication. Its client-key and certificate are provided by Google. I also need to setup JMX agent with SSL on same application whose certificates are provide
Working with clobs in webapps using tomcat and mysql seems to be very easy. For the following example we assume we have the table 'mytable' with a clob 'myclob' and a key 'id' This is an example to how to put a byte array inside a clob: Connection co
I have created a single jar for Java 7 & 8 for a JDBC driver (using -source/-target compile options). However, I am having difficulty compiling applications that use the new/overloaded methods in the ResultSet interface: //New in Java 8 updateObject(
I am trying to write a very simply query using the PreparedStatement class. I read here:Fail to convert to internal representation JDBC that you cannot parameterize column names, only values. Since my query is very simple, the only 'value' I can para
This question already has an answer here: Number of days between two dates in Joda-Time 6 answers I need some help guys, i want to make a program that will be used to control the expiration date of some products, it will need to compare the system da
I'm using Spring connecting to Sql Server 2008 R2 via JDBC. All I need is to insert a large amount of data to a table in the database as fast as possible. I'm wondering which way is better: Use Spring batch insert mention here Create stored procedure
Using SQLFiddle, PostgreSQL 9.3.1. I am learning to define triggers in PostgreSQL, and after doing some research I've found out the following: Triggers in Postgres are different from MYSQL. Where in Postgres you must create a function that RETURNS TR
I was recently asked this question in an interview. Q1 : Where should you close a database connection in a servlet? A : Ideally, and in most practical applications that I have come across, a database connection is closed in the Finally block. Q2: Why
Question: Updated: Why does inserting a row into table A with a foreign key constraint to table B and then updating the row in table B that the inserted row in table A references in a transaction cause a deadlock? Scenario: reservation.time_slot_id h
I am trying to update a table in the database where i m accepting fees from the students and maintaining the record of the amount received, total amount received, and the mode of payment etc. my code is as follows: private void pay_saveActionPerforme
I have an existing eclipse project (JAVA application), now I created a table in xampp - phpMyAdmin. In the project I need to implement all the queries and database in two ways: 1) JDBC 2) JPA and to choose one of them using the Spring mechanism. So I
I have problem with creating tables by JDBC controller on Oracle database. When I create table by "creata table...." is ok. Table create and I see that table by SQL Developer. I have method to check if table with that name exist - and it works g
I have some Java code like int userid = take user input; And then execute following sql statement, Class.forName(dbdriver); conn = DriverManager.getConnection(url, username, password); st = conn.createStatement(); st.executeUpdate("select * from pers
I am creating a web page where user can select datasource and execute select statements and see the paginated results in table. Now for pagination i am wrapping queries to get total row count and rownum to fetch a particular block of rows. As we add
I have some c3p0 pool encapsulated in a class that I use to execute SQL statements. It's initialized this way: public PooledQueryExecutor(String url, Properties connectionProperties) throws DALException { try { dataSource = new ComboPooledDataSource(
Currently, using JDBC, if I want to set a database column to a timestamp value and have the database interpret it as a UTC timestamp, I would do this: PreparedStatement pst = connection.prepareStatement(sql); pst.setTimestamp(1, timestampValue, Calen
I looked for a similar question, but only found similar ones such as Godaddy JNDI Problem---Cannot create JDBC driver of class '' for connect URL 'null' which doesn't answer my generic question. Tomcat 7.0.8 .. the following code Context initialConte
Basic information: Ruby version : 1.8.7 JRuby version: 1.5.3 Rails version: 2.3.5 Mysql version: Ver 14.14 Distrib 5.1.48, for apple-darwin10.3.0 (i386) using readline 5.1 I've been having a hell of a time trying to get JRuby, Rails, and MySQL to pla
I'm writing a Java application that's working with Apache Derby via JDBC. I'm having problems with the code in the following snippet: byte md5[] = md5sum(file); PreparedStatement s = con.prepareStatement("INSERT INTO input_files (job_ID, hash) SELECT
I'm working on an application to do some batch processing, and want to store the input and output data as files in BLOB fields in an Oracle database. The Oracle version is 10g r2. Using the PreparedStatement.setBinaryStream() method as below will ins
When I ran my web application under Eclipse IDE everything worked fine. But when I exported my project into war-file and deployed in tomcat I've got following message: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc I've tried putting
I need to test a JDBC connection to a database. The java code to do that should be as simple as: DriverManager.getConnection("jdbc connection URL", "username", "password"); The driver manager will lookup the appropriate the d