Questions tagged [jdbc]

2

votes
1

answer
12.3k

Views

Calling Oracle PL/SQL stored procedure from java middle tier using JDBC on Linux?

Newbie question... Can anyone provide a high level description of what things need to be done in a PL/SQL stored procedure (residing in a database Linux server) to send data to a Java program (in an application server)? UPDATE 1 elrado's answer below moved me forward (thanks!). I can see that the P...
ggkmath
1

votes
1

answer
26

Views

My second table isn't being filled with data

Alright.. So I've made a small application which makes a connection to my database. I can read out an excel file and store those files into an array. My database has multiple tables. I can fill in one table, but when I want to fill in the other table aswell, it won't work. I get a load of red lines...
Wout
1

votes
1

answer
218

Views

Repeated retrieval in result set returns null

I'm having an issue with ResultSet.getString where when I call it the first time it returns the value but the second time returns null (this without closing the resultset or the sql connection) if (rs.getString(i) == null) { properties.setProperty(metaData.getColumnLabel(i), ''); } else { properties...
phury
5

votes
8

answer
9.7k

Views

Connection to Oracle without a username or password

Oracle has this concept of allowing database users to be identified by the operating system user who is running the program that is connecting to Oracle. See here. This allows you to do, as that user on a unix machine for example, a command such as: sqlplus / I am attempting to write a Java program...
Jamie Love
2

votes
1

answer
1.2k

Views

Cannot find symbol using DriverManager.getConnection()

I have this code below, where I use DriveManager to manage my database driver. public static void main(String[] args)throws SQLException { Connection con = new DriverManager.getConnection('jdbc:hsqldb:hsql://localhost/first-example','SA',''); } But Im having an error with .getConnection(), the e...
UserX
5

votes
4

answer
6.1k

Views

persist java LocalDate in MySQL

I'm writing a java client application using: SE 8, MySQL 5.6 (Connector/J 5.1), JPA 2.1. when I try to persist an entity with an ID (int Auto-increment), date (LocalDate). it throw an Exception says: Internal Exception: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '\xAC...
usertest
21

votes
6

answer
1.5k

Views

How best to modernize the 2002-era J2EE app?

I have this friend.... I have this friend who works on a java ee application (j2ee) application started in the early 2000's. Currently they add a feature here and there, but have a large codebase. Over the years the team has shrunk by 70%. [Yes, the 'i have this friend is'. It's me, attempting to hu...
user331465
2

votes
2

answer
7.7k

Views

Hibernate is rounding my double?

I've got a double which I'm trying to save to a postgres numeric column. The value I'm trying to save is 151.33160591125488, and I've verified that this is in fact the argument being received by Hibernates internals pre-insert. However the value in the database post insert is 151.331605911255, ie it...
pstanton
3

votes
5

answer
3k

Views

ThreadLocal + java.sql.Connection + servlet filter = 2009?

I am writing some servlets with plain old mostly-JDBC patterns. I realized that I have several objects that would like to share a single transaction, and I'd like to enforce that one HTTP transaction = one database transaction. I think I can do this via passing a Connection around in a ThreadLocal v...
sehugg
3

votes
1

answer
27.1k

Views

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver : Am I loading the right driver?

When I run the following snippet to connect to datasource to get the data out through queries : try { String driver = 'com.microsoft.jdbc.sqlserver.SQLServerDriver'; Class.forName(driver); String Url = 'jdbc:sqlserver://localhost:1433;databaseName=movies'; Connection connection = DriverManager.getCo...
Y.E.P
2

votes
1

answer
9.8k

Views

Error while registering Oracle JDBC Diagnosability MBean

When I'm using ojdbc6.jar for my application. I'm getting some weird error. Could anyone help me to solve this error ? Here is complete stack trace of exception raised during my application execution Sep 20, 2013 4:05:36 PM oracle.jdbc.driver.OracleDriver registerMBeans SEVERE: Error while register...
Ravi
5

votes
4

answer
4.4k

Views

Spring Integration as embedded alternative to standalone ESB

Does anybody has an experience with Spring Integration project as embedded ESB? I'm highly interesting in such use cases as: Reading files from directory on schedule basis Getting data from JDBC data source Modularity and possibility to start/stop/redeploy module on the fly (e.g. one module can scan...
FoxyBOA
7

votes
3

answer
11.1k

Views

Is this use of PreparedStatements in a Thread in Java correct?

I'm still an undergrad just working part time and so I'm always trying to be aware of better ways to do things. Recently I had to write a program for work where the main thread of the program would spawn 'task' threads (for each db 'task' record) which would perform some operations and then update t...
ArturPhilibin
2

votes
1

answer
4.6k

Views

Spring service will not start

Working on a basic Spring REST service, but I seem to have a problem with running the service due to JDBC. I have followed a simple tutorial, but at the end the following error log comes up. Error log :: Spring Boot :: (v1.2.5.RELEASE) 2015-09-20 13:53:55.495 INFO 2120 --- [lication.main()]...
Lars
1

votes
2

answer
14.2k

Views

Trouble connecting to a remote HANA database via JDBC

I'm running a small JAVA program from my laptop trying to connect via JDBC to our HANA server for a 'Can we?' prototype. I understand it's possible to connect via JDBC connection to a remote HANA server. However, I cannot. Here's the methodology I'm using from the JAVA using the sapdbc.jar file. I...
Davidson
3

votes
6

answer
1.8k

Views

Java Desktop Application to connect to database

I have a desktop application and it makes use of JDBC. I have no problem with JDBC whenever I use localhost. Now, I am to connect to a server that does not allow remote connection. I was advised to provide a web service to serve as a gateway between my application and the database. An alternative so...
user974227
2

votes
1

answer
547

Views

Batch insertion in JDBC

For bulk insertion we normally prefer BATCH operation. How exactly is it optimized for faster insertion in jdbc ?
UVM
19

votes
1

answer
27.1k

Views

JDBC connection default autoCommit behavior

I'm working with JDBC to connect to Oracle. I tested connection.setAutoCommit(false) vs connection.setAutoCommit(true) and the results were as expected. While by default connection is supposed to work as if autoCommit(true) [correct me if I'm wrong], but none of the records are being inserted till...
stackex
5

votes
2

answer
6.6k

Views

Android - Access to online Database SQlite

I need to open, read and insert items into an online SQLite database from an Android app. I know url, username and password. In JavaSE i would do the following: Class.forName('com.mysql.jdbc.Driver'); Connection dbConnection = DriverManager.getConnection(URL, USER, PASSWORD); I read that I can't do...
Oneiros
2

votes
2

answer
8.4k

Views

How to configure DBCP PoolableConnectionFactory?

This is how I create a DataSource with DBCP 1.4 connection factory: PoolableConnectionFactory factory = new PoolableConnectionFactory( new DriverManagerConnectionFactory('jdbc:h2:mem:db', '', ''), new GenericObjectPool(null), null, 'SELECT 1', false, true ); DataSource src = new PoolingDataSource(fa...
yegor256
3

votes
4

answer
4.3k

Views

Why is my datetime parameter for a stored procedure being rejected?

I’m working on a Java server app which uses Spring 3 and C3P0 to access a Microsoft SQL Server 2008 R2 database, using version 3.0 of Microsoft’s JDBC 4 driver. I have a sproc which has an input defined like so: @modifiedAfter datetime = NULL I’m using Spring to construct a call to this sproc....
Avi Flax
42

votes
6

answer
119.9k

Views

Converting java.sql.Date to java.util.Date

What's the simplest way to convert a java.sql.Date object to a java.util.Date while retaining the timestamp? I tried: java.util.Date newDate = new Date(result.getDate('VALUEDATE').getTime()); with no luck. It's still only storing the date portion into the variable.
mservidio
14

votes
1

answer
1.4k

Views

Is it good to put jdbc operations in actors?

I am building a traditional webapp that do database CRUD operations through JDBC. And I am wondering if it is good to put jdbc operations into actors, out of current request processing thread. I did some search but found no tutorials or sample applications that demo this. So What are the cons and p...
xiefei
3

votes
1

answer
600

Views

JDBC Connection Pool SSL Error PKIX building failed

This is using the latest Glassfish (4.1), the latest Postgres Driver (9.3-1102 JDBC 41) against Postgres 9.4, and the latest Java (1.8.0_31-b13). This is also using a commercial CA certificate, I have checked the CA root is present in $JAVA_HOME/jre/lib/security/cacerts. For good measure I have als...
Little Code
4

votes
3

answer
15.3k

Views

Running SQL files scripts from a Java program

I have a set of SQL files that transform my original dataset. Currently, I open each file and execute it. How can I execute each file inside a Java program? The goal is to make this process a lot more automatic. I would like to do something like SqlScript.execute('myScript.sql'); NOTE these SQL scr...
CodeKingPlusPlus
2

votes
1

answer
666

Views

jdbc mysql giving me NumberFormatException

I am trying to connect to a remote mysql database but I get the following error java.sql.SQLException: Cannot connect to MySQL server on biomancy.com:3306. Is here a MySQL server running on the machine/port you are trying to connect to? ( ava.lang.NumberFormatException) at org.gjt.mm.mysql.Connectio...
lathomas64
2

votes
1

answer
21.7k

Views

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1

I m getting the below SQL exception and I don't know what's the root cause for this exception? I am also closing db connection and statement too. java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-01000: maximum open cursors exceeded ORA-00604: error occurred at recursive...
praveen2609
11

votes
5

answer
6.1k

Views

How to use Java JDBC connection pool?

I want to use a JDBC connection pool. The most important factor is that it's easy-to-use and bug-free. What is suitable for me?
Shayan
1

votes
2

answer
8.6k

Views

how to compile mysql JDBC driver with a java file in cmd

I want to compile .java file with MYsql JDBC Connector This is where the .jar file is D:\mysql-connector-java-5.1.31-bin.jar This is what I used to compile... javac -cp 'D:\mysql-connector-java-5.1.31-bin.jar' LocationServer.java Code for LocationServer.java import java.rmi.Naming; import java.rmi...
Karedia Noorsil
13

votes
2

answer
157

Views

Query MySQL DB using preparedStatement.setDate

public java.util.List getAlltagsByDate(String date ){ DataSource dataSource = new DataSource(); Connection conn = dataSource.createConnection(); ResultSet resultSet = null; PreparedStatement stmt = null; Tag tags_Data = new Tag(); String query = 'select * from tag_data where tag_data_date = ?'; tr...
mohit sharma
2

votes
2

answer
4.4k

Views

java.sql.SQLData - Oracle object mapping problem

I am using java.sql.SQLData interface to map my java objects to Oracle database types. For example, I have an object type Person in Oracle DB defined as: CREATE OR REPLACE TYPE PERSON AS OBJECT ( PERSON_ID NUMBER, PERSON_NAME VARCHAR2(100) ); Corresponding Java type is: public class Person implement...
Sid
1

votes
1

answer
13.9k

Views

Too many connections with Spring + MyBatis + MySQL + JDBC

I am trying to work with spring, mybatis and mysql with jdbc. The only small problem I have after some queries, it throws an exception. The DB says: Too many connections. So what I am trying to do to prevent the too many connection issue is to set up a connection pool. I have tried dbcp and bonecp a...
Zoltan Szabo
3

votes
2

answer
1.4k

Views

CREATE DATABASE query using java jdbc and prepared statement returns syntax error

I am trying to get Java to create a database using JDBC but I get a syntax error, despite the query being correct. If I write the name of a database into the code explicitly, for example, it works fine. Here's my code: package mysql_manipulator; import java.sql.Connection; import java.sql.DriverMana...
Dylan White
2

votes
1

answer
1.8k

Views

JDBC SQL aliasing not working

I am trying to run the following query in my java web application: SELECT platform AS 'Platform' FROM edb.cases The web-app is working fine and is able to execute all queries however whenever I use an alias (through 'AS'), the resultant data-set gives me a null value for the alias. In fact, despite...
Deepak
3

votes
2

answer
847

Views

Sqoop + Postgresql: how to prevent quotes around table name

I am trying to import a table from Postgresql to a Parquet file on HDFS. Here is what I do: sqoop import \ --connect 'jdbc:postgresql://pg.foo.net:5432/bar' \ --username user_me --password $PASSWORD \ --table foo.bar \ --target-dir /user/me/bar \ --as-parquetfile and I get INFO manager.SqlManager: E...
2

votes
3

answer
211

Views

Getting exception on running a jar- “Exception in thread ”main“ java.lang.ClassNotFoundException: com.mysql.jdbc.Driver” [duplicate]

This question already has an answer here: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when executing JAR 3 answers I have gone through all the suggested questions, still no solution. I am running a java program of jdbc connection on eclipse, its giving the required result but when makin...
dexter
2

votes
1

answer
181

Views

In debug mode I can see extra array list elements and are initialized to zero

I am fetching some data from database using simple jdbc call and when I am debugging my application, it is showing some extra record which are null. Actual size of my list should be 138 but its initializing 171 as array size. As I am using collection named LDCBeanCollection which extends ArrayList a...
ashishraaj
3

votes
1

answer
231

Views

How to get the last 3 distinct ids from a mysql table

Ok so basically I have my database table. The first column is the id. The second is a pkg_id. The 3rd is not important and the 4th is the previous id that the pkg_id was located at. I need to pull the last 3 pkg_id's from the table. So basically I need to pull the last 3 17879 pkg_id's and the...
Drew H
3

votes
1

answer
2.1k

Views

SQL Server Nvarchar and Java prepared statement

I have a question regarding inserting strings to SQL Server 2008 R2. When I try to insert strings with some national letters, I receive '?' instead. I know that adding N at the beginning of a string literal will fix this problem, but I'm using JDBC prepared statements, like this: INSERT INTO MyTabl...
PastorPL
462

votes
5

answer
258.8k

Views

java.util.Date vs java.sql.Date

java.util.Date vs java.sql.Date: when to use which and why?
flybywire