Questions tagged [jdbc]

11373 questions
92

votes
8

answer
580.8k

Views

java.net.SocketException: Connection reset

I am working on a spring related application using PostgreSQL. While I am trying to click the tabs in UI, I am getting this error. I know this is old question which is asked by so many people but those answers couldn't help to me. So I am raising this question again Please help me. SEVERE: Servlet....
mahesh chinta
165

votes
25

answer
525k

Views

Solving a “communications link failure” with JDBC and MySQL [duplicate]

This question already has an answer here: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 30 answers I'm trying to connect to the local MySQL server but I keep getting an error. Here is the code. public class Connect { public static void main(String[] args) { Co...
Anthony
207

votes
7

answer
475k

Views

Java JDBC - How to connect to Oracle using Service Name instead of SID

I have a Java application that uses JDBC (via JPA) that was connecting to a development database using hostname, port and Oracle SID, like this: jdbc:oracle:thin:@oracle.hostserver1.mydomain.ca:1521:XYZ XYZ was the Oracle SID. Now I need to connect to a different Oracle database that does not use a...
Jim Tough
280

votes
12

answer
471.6k

Views

Connect Java to a MySQL database

How do you connect to a MySQL database in Java? When I try, I get java.sql.SQLException: No suitable driver found for jdbc:mysql://database/table at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:247) Or java.lang.ClassNotFou...
abson
169

votes
30

answer
462.9k

Views

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

I'm working on getting my database to talk to my Java programs. Can someone give me a quick and dirty sample program using the JDBC? I'm getting a rather stupendous error: Exception in thread 'main' com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet...
Josh K
87

votes
15

answer
404.7k

Views

How to convert TimeStamp to Date in Java?

How do I convert 'timeStamp' to date after I get the count in java? My current code is as follows: public class GetCurrentDateTime { public int data() { int count = 0; java.sql.Timestamp timeStamp = new Timestamp(System.currentTimeMillis()); java.sql.Date date = new java.sql.Date(timeStamp.getTime()...
Krishna Veni
85

votes
21

answer
404.1k

Views

How to fix: “No suitable driver found for jdbc:mysql://localhost/dbname” error when using pools? [duplicate]

This question already has an answer here: The infamous java.sql.SQLException: No suitable driver found 9 answers I am trying to create a connection to my database, when I put test my code using the main method, it works seamlessly. However, when trying to access it through Tomcat 7, it fails with e...
Tamer
252

votes
14

answer
389.9k

Views

How do I get the size of a java.sql.ResultSet?

Shouldn't this be a pretty straightforward operation? However, I see there's neither a size() nor length() method.
Jake
269

votes
21

answer
379.2k

Views

Java ResultSet how to check if there are any results

Resultset has no method for hasNext. I want to check if the resultSet has any value is this the correct way if (!resultSet.next() ) { System.out.println('no data'); }
kal
47

votes
8

answer
374.7k

Views

How do I connect to a SQL Server 2008 database using JDBC?

I have MSSQL 2008 installed on my local PC, and my Java application needs to connect to a MSSQL database. I am a new to MSSQL and I would like get some help on creating user login for my Java application and getting connection via JDBC. So far I tried to create a user login for my app and used follo...
taras
259

votes
16

answer
334.8k

Views

Find Oracle JDBC driver in Maven repository

I want to add the oracle jdbc driver to my project as dependency (runtime scope) - ojdbc14. In MVNrepository site the dependency to put in the POM is: com.oracle ojdbc14 10.2.0.3.0 of course this does't work as it is not in the central repository used by maven. 2 questions: How do I find a repositor...
rperez
103

votes
8

answer
321.1k

Views

How do I find out my MySQL URL, host, port and username?

I need to find my MySQL username. When I open the MySQL command line client, it only asks me for my password. I don't remember my username. And for connectivity with JDBC, I need the URL, host and port number. Where do I find all of these?
68

votes
16

answer
319.1k

Views

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse

What is wrong with the code there are lots of error while debugging. I am writing a code for a singleton class to connect with the database mysql. Here is my code package com.glomindz.mercuri.util; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQL...
atikul hussain
57

votes
13

answer
311k

Views

How to get row count using ResultSet in Java?

I'm trying to create a simple method that receives a ResultSet as a parameter and returns an int that contains the row count of the ResultSet. Is this a valid way of doing this or not so much? int size = 0; try { while(rs.next()){ size++; } } catch(Exception ex) { System.out.println('---------------...
Tiwaz89
291

votes
14

answer
309.4k

Views

To prevent a memory leak, the JDBC Driver has been forcibly unregistered

I am getting this message when I run my web application. It runs fine but I get this message during shutdown. SEVERE: A web application registered the JBDC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Dr...
mona
102

votes
10

answer
298.7k

Views

What is the MySQL JDBC driver connection string?

I am new to JDBC and I am trying to make a connection to a MySQL database. I am using Connector/J driver, but I cant find the JDBC connection string for my Class.forName() method.
47

votes
9

answer
287.6k

Views

No suitable driver found for 'jdbc:mysql://localhost:3306/mysql [duplicate]

This question already has an answer here: The infamous java.sql.SQLException: No suitable driver found 9 answers Using Java, I get this error when attempting to connect to a mysql database: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysql at java.sql.DriverMana...
user994165
307

votes
27

answer
282.3k

Views

PreparedStatement IN clause alternatives?

What are the best workarounds for using a SQL IN clause with instances of java.sql.PreparedStatement, which is not supported for multiple values due to SQL injection attack security issues: One ? placeholder represents one value, rather than a list of values. Consider the following SQL statement: SE...
Chris Mazzola
191

votes
10

answer
273.6k

Views

Retrieve column names from java.sql.ResultSet

With java.sql.ResultSet is there a way to get a column's name as a String by using the column's index? I had a look through the API doc but I can't find anything.
95

votes
13

answer
267.9k

Views

java.sql.SQLException: - ORA-01000: maximum open cursors exceeded

I am getting an ORA-01000 SQL exception. So I have some queries related to it. Are maximum open cursors exactly related to number of JDBC connections, or are they also related to the statement and resultset objects we have created for a single connection ? (We are using pool of connections) Is there...
Kanagavelu Sugumar
51

votes
10

answer
261.1k

Views

No more data to read from socket error

We are using Oracle as the database for our Web application. The application runs well most of the time, but we get this 'No more data to read from socket' error. Caused by: java.sql.SQLRecoverableException: No more data to read from socket at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngin...
Kathir
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
340

votes
11

answer
240.3k

Views

How to get the insert ID in JDBC?

I want to INSERT a record in a database (which is Microsoft SQL Server in my case) using JDBC in Java. At the same time, I want to obtain the insert ID. How can I achieve this using JDBC API?
Satya
82

votes
9

answer
239k

Views

Oracle JDBC ojdbc6 Jar as a Maven Dependency

I cannot seem to get Maven to bundle the ojdbc6.jar file into my project's war file. I have it working within the POM file when specifying a dependency directly for Hibernate tools. But it won't get bundled with the project's war file, and therefore my project won't run on Tomcat. I have tried eve...
Marvo
48

votes
17

answer
238.1k

Views

TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

I'm trying to connect to Oracle 10.2.0 from NetBeans, using the following connection string: jdbc:oracle:thin:@localhost:1521:XE The weirdest part is that everything worked fine, until the one of the reboots. I started getting this TNS-12505 errors all the time; look at the final entries in my liste...
Anton
140

votes
8

answer
237.5k

Views

Get query from java.sql.PreparedStatement [duplicate]

This question already has an answer here: How can I get the SQL of a PreparedStatement? 13 answers In my code I am using java.sql.PreparedStatement. I then execute the setString() method to populate the wildcards of the prepared statement. Is there a way for me to retrieve (and print out) the final...
llm
34

votes
15

answer
227.2k

Views

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

The following code: Class.forName('com.mysql.jdbc.Driver'); Connection m_connection = DriverManager.getConnection('jdbc:mysql://localhost','root','root'); Throws this exception on getConnection(): java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdb...
ron
156

votes
13

answer
225.2k

Views

“Incorrect string value” when trying to insert UTF-8 into MySQL via JDBC?

This is how my connection is set: Connection conn = DriverManager.getConnection(url + dbName + '?useUnicode=true&characterEncoding=utf-8', userName, password); And I'm getting the following error when tyring to add a row to a table: Incorrect string value: '\xF0\x90\x8D\x83\xF0\x90...' for column 'c...
Lior
34

votes
9

answer
223.1k

Views

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname [duplicate]

This question already has an answer here: The infamous java.sql.SQLException: No suitable driver found 9 answers I have this Java program: MySQLConnectExample.java import java.sql.*; import java.util.Properties; public class MySQLConnectExample { public static void main(String[] args) { Connection...
user3416261
192

votes
14

answer
216.3k

Views

Difference between Statement and PreparedStatement

The Prepared Statement is a slightly more powerful version of a Statement, and should always be at least as quick and easy to handle as a Statement. The Prepared Statement may be parametrized Most relational databases handles a JDBC / SQL query in four steps: Parse the incoming SQL query Compil...
SO_Bee
131

votes
13

answer
206.2k

Views

How can I get the SQL of a PreparedStatement?

I have a general Java method with the following method signature: private static ResultSet runSQLResultSet(String sql, Object... queryParams) It opens a connection, builds a PreparedStatement using the sql statement and the parameters in the queryParams variable length array, runs it, caches the Res...
froadie
41

votes
5

answer
201.6k

Views

java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver

I'm getting this exception when I try to run this program. It's one of the Microsoft examples. I've added the sqljdbc4.jar to the classpath in netbeans for both compile and Run, via the project properties. I also tested that the class could be found by using an import statement below - no error duri...
Larry Watanabe
32

votes
21

answer
196.7k

Views

ClassNotFoundException com.mysql.jdbc.Driver

This question might have asked here number of times . After doing some google search for the above error and doing some update, I can't understand why I'm still getting that error. I've already put my driver-- mysql-connector-java-5.1.5-bin in the classpath: Java_Home\jre\lib\ Java_Home\jre\lib\ext\...
Dusk
32

votes
6

answer
190.7k

Views

URL string format for connecting to Oracle database with JDBC

I'm a newbie to Java-related web development, and I can't seem to get a simple program with JDBC working. I'm using off-the-shelf Oracle 10g XE and the Eclipse EE IDE. From the books and web pages I've checked so far, I've narrowed the problem down to either an incorrectly written database URL or a...
Pops
66

votes
15

answer
190.3k

Views

PreparedStatement with list of parameters in a IN clause [duplicate]

This question already has an answer here: PreparedStatement IN clause alternatives? 27 answers How to set value for in clause in a preparedStatement in JDBC while executing a query. Example: connection.prepareStatement('Select * from test where field in (?)'); If this in-clause can hold multiple va...
Harish
66

votes
5

answer
188.4k

Views

JDBC connection failed, error: TCP/IP connection to host failed

I want to connect Java class file with SQL server 2012. I have logged in with SQL server authentication. But i am receiving error in connectivity. ERROR: The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: 'Connection refused: connect. Verify the connection properties. Make sur...
Aysha Nijhawan
301

votes
15

answer
187.2k

Views

Connection pooling options with JDBC: DBCP vs C3P0

What is the best connection pooling library available for Java/JDBC? I'm considering the 2 main candidates (free / open-source): Apache DBCP - http://commons.apache.org/dbcp/ C3P0 - http://sourceforge.net/projects/c3p0 I've read a lot about them in blogs and other forums but could not reach a decis...
Dema
52

votes
5

answer
186.3k

Views

Can I connect to SQL Server using Windows Authentication from Java EE webapp?

I am currently investigating how to make a connection to a SQL Server database from my Java EE web application using Windows Authentication instead of SQL Server authentication. I am running this app off of Tomcat 6.0, and am utilizing the Microsoft JDBC driver. My connection properties file looks a...
karlgrz
18

votes
7

answer
186.2k

Views

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver [duplicate]

This question already has an answer here: How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib 4 answers I wrote a Java Servlet program but when I run it, it was showing the Exception java.lang.ClassNotFoundException: orac...
19

votes
8

answer
183.1k

Views

IO Error: The Network Adapter could not establish the connection

I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong? Update: I am using JDBC. Datab...
Strawberry