Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all 884 articles
Browse latest View live

MysqlConnectionPoolDataSource - Can not insert to mysql db using jdbc? (no replies)

$
0
0
I have to use a custom jdbc connection pooling library to connect to mysql db.

The problem is my that inserts are not persisted in db... To narrow down the issue, I extracted the portion of the library code inserting into db and have some strange findings:

MysqlConnectionPoolDataSource ds1 = new MysqlConnectionPoolDataSource();
ds1.setUser("usr");
ds1.setPassword("pwd");
ds1.setServerName("server");
ds1.setPort(port);
ds1.setDatabaseName("dbname");
ds1.setUseSSL(false);
ds1.setAllowPublicKeyRetrieval(true);


Connection conn = ds1.getPooledConnection("usr", "pwd").getConnection();

logger.info("connection " + conn.toString());

PreparedStatement ps = null;
ResultSet rs = null;

try {

String query = "INSERT INTO ...";
ps = conn.prepareStatement(query);

int timeout = 10;
ps.setQueryTimeout(timeout);

logger.info("timeout: " + timeout);
logger.info("Starting query execution for query: " + query);
long qeStart = System.currentTimeMillis();

ps.setString(1, "...");

ps.executeUpdate();

long qeEnd = System.currentTimeMillis();
logger.info("Query execution completed in " + (qeEnd - qeStart) + "msec.");
} catch (Exception e) {
logger.error("ERROR OCCURED", e);
System.err.println("ERROR OCCURED");
e.printStackTrace();

} finally {
closeResultSet(rs);
closeStatement(ps);
closeConnection(conn);
}

The above code does NOT work when I connect to a remote mysql db with version: 8.0.11-commercial . By not working I mean there is no error, the insert is simply lost...

When I execute the same code against my local mysql db with version : 8.0.11 hosted on windows machine, it is working...

If I change connection getting code from

Connection conn = ds1.getPooledConnection("usr", "pwd").getConnection();

to:

Connection conn = ds1.getConnection();

it also starts to work against remote mysql db with version: 8.0.11-commercial...

The autocommit mode of the underlying connection is already true...

I tried to implement a custom log4j logger with the hope of seeing some trace but that did not help either:

ds1.setLogger("com.ibtech.mysqlproblem.Log4jLogger");
My custom connection pooling library uses pooled connection so I need to get the above code working. In the client I am using mysql-connector-java-8.0.11.jar.

Any help is greatly appreciated...

Data truncation on longblob field (no replies)

$
0
0
I get the error SQLError: 1406 Data truncation: Data to long for column 'fileBuffer' ... when i try to insert more than 255 bytes in a longblob column.
The column fileBuffer has longblob data type.
I am using the mysql connector for java ver. 5.1.46 and my mysql server is
Ver 14.14 Distrib 5.7.21, for osx10.13.
The table that has the problem has been created by hibernate
The creation statement is:

CREATE TABLE `FileData` (
`id` int(11) NOT NULL,
`descrSize` varchar(255) DEFAULT NULL,
`errorRecords` int(11) NOT NULL,
`fileName` varchar(255) DEFAULT NULL,
`importedRecords` int(11) NOT NULL,
`loadedTs` tinyblob,
`totRecords` int(11) NOT NULL,
`ente_id` int(11) NOT NULL,
`utente_id` int(11) NOT NULL,
`fileBuffer` longblob,
PRIMARY KEY (`id`),
KEY `FKsf2ufvp5e3p5vv3ax7krmlwd4` (`ente_id`),
KEY `FKf2p7052rcbaw2k309ma2xp2t8` (`utente_id`),
CONSTRAINT `FKf2p7052rcbaw2k309ma2xp2t8` FOREIGN KEY (`utente_id`) REFERENCES `Utente` (`id`),
CONSTRAINT `FKsf2ufvp5e3p5vv3ax7krmlwd4` FOREIGN KEY (`ente_id`) REFERENCES `Ente` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


This is the java code that inserts the blob:

FileData fd = new FileData(); //this is a Hibernate entity
...
fbuffer = new byte[256];
Blob blob = Hibernate.getLobCreator(jpaApi.em().unwrap(org.hibernate.Session.class)).createBlob(fbuffer);

fd.setFileBuffer(blob);

...

jpaApi.em().persist(fd);

when the transaction commit i get the error.
if filebuffer is less then 256 bytes it works without errors


thanks in advance

Issue with Java 10/J-connector/MySQL need possible fix by Oracle (no replies)

$
0
0
Hello everyone,

I have recently wrote on forum the Oracle website an issue that is caused within Java Database Connectivity in Java 10, J-Connector, and MySQL version 8. It is regarding a syntax error that needs to be fixed by Oracle and MySQL themselves. Who do I report to this case? Below is the URL containing my thread regarding the issue, I also have documentation pertaining to the problem.


https://community.oracle.com/message/14840887#14840887

Does MySQL work with Java 10 and XQuery (no replies)

$
0
0
Recently I was working with the eXist Database program. Version 4.0 currently doesn't work with Java 10. I'm sure they will fix this someday, but I need to perform database work right now. Does MySQL work with Java 10 and XQuery?

Connector 8.0 and LocalDate timestamp issue (no replies)

$
0
0
Hi guys,

I'm facing a problem with mysql connector and LocalDate - the new class from Java.time package.

LocalDate has as attributes day, month and year, but once I try to save it in the database, it seems that the connector also takes into consideration the time zone (in the db, it is a date).

For example, I want to save a LocalDate expiration date 2020-05-20, but if I change the local zone on my machine, sometimes it saves 2020-05-19.

By the way, I can't have database and server at the same timezone. It's a global application, and I just want to tell the connector to don't touch the timezone.

Solutions like useLegacyDatetimeCode=false didn't work for me. The only workaround that works is to format from LocalDate to String, and save it to the database. But I'd like to have a more elegant solution (if that exists).

Thanks!!

Ricardo Lima

ConnectorJ and MySQL MASTER-SLAVE replication (no replies)

$
0
0
Hi,

could anyone explain me how the connectorJ interact with the MySQL MASTER-SALVE configuration?

COuld I use the library to promote a slave to a master? I have tested some code but the library do not affect the replica configuration....

In addition the connection object fail when one HOST is down....I'm using connectJ 8 and I already set the param allowMasterDown and allwSlaveDown....

Best Regards

Admin Properties for MySQL 8.0 in Netbeans (no replies)

$
0
0
I am trying to register my new mySQL db in Netbeans, and unsure what the admin properties should be for:

Path/URL to admin tool;
Path to start command;
Path to stop command;

I am currently using"..\MySQLWorkbench.exe" as the admin tool, "...\MySQL Server 8.0\bin\mysqld.exe" for the start path, and "...\MySQL Server 8.0\bin\mysqladmin.exe" with an argument of "-u root stop"

I am getting an error:

no enum constant com.mysql.cj.conf.PropertyDefinitions.ZeroDatetimeBehavior.CONVERTTONULL

Does anyone know how to fix this? Are my setting correct?

Connector/J 8, catching primary key violations (no replies)

$
0
0
How do I go about catching primary key violations using the new version of Connector/J? In 5.1 I was able to catch com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException and handle it accordingly.

That class no longer exists in 8.0, and looking through the jar I don't see any analogous exception. Not only that, there's nothing in the upgrade guide that mentions that the previous exception classes have been removed and what to use instead.

ResultSet.wasNull reports false for getBytes when value is null (1 reply)

$
0
0
I have a tables with nullable blob columns. When reading from a result set using CJ 5.1 I have been able to use ResultSet.getBytes() and check ResultSet.wasNull() before operating on the byte[].

Since upgrading to CJ 8.0, this no longer works. wasNull() is returning false when getBytes() is returning null for a null value. For a non-null value everything is ok.

Bug or should I not be using getBytes for a blob?

Column Type for mysql float (no replies)

$
0
0
Hello,

when I use the Connector/J driver, I get a java.sql.Types code 7 (incorrect?) with calling getColumnType() for a mysql float data type. I created a simple example to reproduce this: (the interesting field is the "myFloat" field).

CREATE TABLE `myTable` (
`id` int(11) NOT NULL,
`myval` varchar(45) DEFAULT NULL,
`myFloat` float DEFAULT NULL,
`myDouble` double DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The Java test program:

public static void main(String[] args) throws Exception {
String driver = "com.mysql.cj.jdbc.Driver";
String connString = "jdbc:mysql://localhost:3306/mydb?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";

Class.forName(driver);
Connection connection = DriverManager.getConnection(connString, "root", "myPassword");

Statement statement = connection.createStatement();

//Query
ResultSet resultSet = statement.executeQuery("select * FROM myTable");
resultSet.next();

ResultSetMetaData rsmd = resultSet.getMetaData();

//Get number of columns returned
int numOfCols = rsmd.getColumnCount();

//Print out type for each column
for(int i=1; i<=numOfCols; ++i)
{
System.out.println("Column [" + i + "] data type: " + rsmd.getColumnTypeName(i) + ", code: " + rsmd.getColumnType(i) + ", " + resultSet.getObject(i).getClass());
}

//Close DB connection
statement.close();
connection.close();

}

The output:
Column [1] data type: INT, code: 4, class java.lang.Integer
Column [2] data type: VARCHAR, code: 12, class java.lang.String
Column [3] data type: FLOAT, code: 7, class java.lang.Float
Column [4] data type: DOUBLE, code: 8, class java.lang.Double

So the FLOAT gets java.sql.Types code 7. But in java.sql.Types I see:
public final static int FLOAT = 6;
public final static int REAL = 7;
public final static int DOUBLE = 8;

Thus, the mysql DOUBLE data type seems to get the correct code (8 in java.sql.Types), but the mysql FLOAT data type should be 6, not 7. Is this a bug?

Using mysql-connector-java-8.0.11.jar and Java 8. With older versions of mysql-connector-java this also happens. Is this a bug?

Thanks,
Edu

MySQL Connector/J 8.0.12 has been released (no replies)

enum mysql.cj.conf.PropertyDefinitions.ZerodatetimeBeha viour.CONVERTTONULL Probleme (no replies)

$
0
0
Hello everybody,
In fact I made an update of my wamp to work on a JEE project, with Netbeans and when I updated the Connector / J I have this error
"enum mysql.cj.conf.PropertyDefinitions.ZerodatetimeBeha viour.CONVERTTONULL".by try to make a connection to mysql.
I have already searched in vain for the solution on the internet but nothing very contructive to solve my problem.
I beg you I have your help.

Thank you in advance.

NB: I'm using Netbeans 8.1 and Connector / j is 8.0

MySQL 4.1.22 Sqoop Connector (no replies)

$
0
0
Does anyone know what version of a MySQL JDBC Connector needs to be used to Sqoop data from a MySQL Server version 4.1.22 to HDFS (CDH version 5.13.1)?

So far, we have tried MySQL Connector/J versions:
- 3.1.14
- 5.0.8
- 5.1.45
- 5.1.46

Thank you!

AddResult getGeneratedIds is useless. (no replies)

$
0
0
After adding a new document into collection successfully, I can not use AddResult.getGeneratedIds to get new ids. It is always [].
AddResult getGeneratedIds is useless.

connect to qws awl data base from android studio (no replies)

$
0
0
i cannot manage to connect to aws sql databas from android studio.
i also cannot manage to conenct to my local host.

this is my code:



public void test(View view) {

Connection conn = null;


try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}


try {

String url = "jdbc:mysql://dbpark.cau22h5s8sgn.us-east-2.rds.amazonaws.com:3306/dbpark";
String user_name = "asafanter";
String password = "1234";
conn = DriverManager.
getConnection(url, user_name, password);

// Do something with the Connection


} catch (SQLException ex) {
// handle any errors
Log.i("SQLException: " , ex.getMessage());
Log.i("SQLState: " , ex.getSQLState());
// Log.i("VendorError: " , ex.getErrorCode());
}


where is the problem?

Im getting following error, help me to resolve this error (no replies)

$
0
0
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
at java.base/java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.base/java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.base/java.net.PlainSocketImpl.connect(Unknown Source)
at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
at java.base/java.net.Socket.connect(Unknown Source)
at java.base/java.net.Socket.connect(Unknown Source)
at java.base/java.net.Socket.<init>(Unknown Source)
at java.base/java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at com.jdbc.Lab1.main(Lab1.java:13)


** END NESTED EXCEPTION **



Last packet sent to the server was 1 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at com.jdbc.Lab1.main(Lab1.java:13)

How do I add the Connector/J location to my Java Classpath on a Mac? (no replies)

$
0
0
I am on a Mac running High Sierra 10.13.6

I downloaded the zip file for the Platform Independent version of Connector/J 8.0.12

I now have a folder in Downloads called mysql-connector-java-8.0.12. There are many things in it, and I’m not sure where to go from here.

The beginning of Chapter 4 of the Guide (https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-installing.html) says, "You can install the Connector/J package using either the binary or source distribution.” I have no idea which I downloaded. There was a zip option and a tar option and I downloaded the zip.

It then goes on to say, "With either solution, you manually add the Connector/J location to your Java CLASSPATH.” How do I do this?

Help with Displaying Chinese in Java from mySQL (no replies)

$
0
0
From Eclipse Java, I run a PHP script which executes a stored procedure in a cloud mySQL database

mySQL Workbench can store and display Chinese characters correctly.

Eclipse returns the dataset correctly in English, but Chinese characters cannot be displayed properly.

This is what I 've tried so far:

(1) In mySQL, I created the table wikth this specification:
ENGINE=INNODB AUTO_INCREMENT= 3 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

(2) In the PHP script, I specified the header like this:
header("Content-type:application/json; charset=UTF-8");

(3) The response is json_encoded, like this:
echo json_encode(array("db_response"=>$response));

(4) And in Eclipse, I've set thre preference to utf-8, like this:
Window -> Preferences -> General -> Workspace -> title file encoding Other UTF-8

Chinese (and other languages) characters are displayed like this on both Firefox and Eclipse-Java app
??????(??)????

All records in English are displayed correctly.

This is the setup I have in mySQL:
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server latin1
character_set_system utf8
collation_connection utf8mb4_unicode_ci
collation_database utf8mb4_unicode_ci
collation_server latin1_swedish_ci

I do not know why the collation_server is set to "swedish"
I do not have a my.ini or my.cnf when I installed mySQL Workbench, so Icreated one myself.

ODBC Connection looses connection to server (no replies)

$
0
0
I have been using Access to connect to a MYSql DB in amazon and recently the connection keeps timing out.

ODBC 5.3(w) Driver][mysqld-5.7.22-log]MySQL server has gone away

I have tried the 8.0 driver and the same thing happens.

Any ideas?

Using URLEncode to upload data via PHP to mYSQL (no replies)

$
0
0
This time around, I am uploading data from the client Java app via PHP to mySQL server. On the PHP end, I am using a _POST and in Java I am using URLEncoder.encode, like this:



ArrayList<String> urlVar = new ArrayList<>();

urlVar.add("?" + (URLEncoder.encode("coyName","UTF-8")+ "=" + URLEncoder.encode(coyName, "UTF-8")));

I am trying to figure out why the above would work, but this won't work (which is what I have been doing).
urlVar.add((URLEncoder.encode("?coyName","UTF-8")+ "=" + URLEncoder.encode(coyName, "UTF-8")));

Moving the ? out of the encode() makes all the difference !?!
Viewing all 884 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>