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

Problems with jdbc Connection on Ubuntu (3 replies)

$
0
0
Hi,
I have a Mysql database running in my machine(Ubuntu 10.10), and with Mysql WorkBench i can log in, but with a jdbc connection I have this error http://imageshack.us/photo/my-images/339/unledhu.jpg/

Server version: 5.1.49-1, in Workbench I have created a Database instance, and it created a connection with the name "localhost"...

I have a punch of users to connect with, and in the workbench I can connect, but through jdbc connection i cannot...

Any one can Help me...
Thanks in advance

I have tried everything I now, but I don’t now what I can make more to solve this problem...

Best regards

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: (no replies)

$
0
0
Hi Friends! I have been designing a desktop application on a windows machine which is meant to interact with a database with a unix socket on the webserver but the following error has blocked me.

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

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection timed out: connect

STACKTRACE:

java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:316)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:177)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:164)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:154)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:390)
at java.net.Socket.connect(Socket.java:578)
at java.net.Socket.connect(Socket.java:527)
at java.net.Socket.<init>(Socket.java:424)
at java.net.Socket.<init>(Socket.java:240)
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.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at System.JTableDatabase.<init>(JTableDatabase.java:34)
at System.JTableDatabase.main(JTableDatabase.java:88)


** END NESTED EXCEPTION **



Last packet sent to the server was 1 ms ago.

My Code is:



/**

* @author King
*/
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.net.ServerSocketFactory.*;
import java.net.ServerSocket.*;
import javax.net.SocketFactory.*;
public class JTableDatabase extends JFrame {
public static Connection conn; //manages connection
public static Statement stm; //query statement
public static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
public static final String DATABASE_URL= "jdbc:mysql://173.193.127.88/xxx+ "";
public static JTable table;
public static JFrame f;
public JTableDatabase(){
Vector columnNames = new Vector();
Vector data = new Vector();
JPanel p=new JPanel();
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DATABASE_URL,"xxxxx", "xxxxx");
String sql = "SELECT * FROM xxxx";
stm = conn.createStatement();
ResultSet rs = stm.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement( md.getColumnName(i) );
}
while (rs.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++){
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stm.close();
}
catch(Exception e){
System.out.println(e);
}
table = new JTable(data, columnNames);
TableColumn col,col1;

for (int i = 0; i < table.getColumnCount(); i++) {
col = table.getColumnModel().getColumn(i);
col1=table.getColumnModel().getColumn(0);
col1.setMinWidth(155);
col.setMaxWidth(250);
col.setResizable(false);
col1.setResizable(false);

}
JScrollPane scrollPane = new JScrollPane( table );
p.add( scrollPane );
f=new JFrame();
JPanel p1=new JPanel();
add(p);
setSize(600,400);
setUndecorated(false);
setLocation(370, 140);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args) {
try
{//com.sun.java.swing.plaf.windows.WindowsLookAndFeel
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}//"com.birosoft.liquid.LiquidLookAndFeel"
catch (Exception ex)
{
JOptionPane.showMessageDialog(null,"Failed loading L&F: ","Error!",JOptionPane.ERROR_MESSAGE);
}
new JTableDatabase().setVisible(true);
}
}




Please help me.

jdbc + MySQL. does not want to run dual select (2 replies)

$
0
0
That is now learning to work with MySQL: I wrote a simple little application that performs SQL-query written in a JTextArea and sends it to MySQL for processing.

So it turned out that the Workbench runs fine the next record:
"select * from test.client;
select * from test.client;"
Returns two identical tables, but in my application does not want to run, gives the following error:
"com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from test.client' at line 2"

Is MySQL can not handle the double request?

To execute the query I use execute()

Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException ex2) {
}
ResultSet rs = null;
boolean resExec = false;
int updCount = 0;
try {
if (wnd.jta1.getSelectedText()!=null) {
System.out.println("\"" + wnd.jta1.getSelectedText() + "\"");
//rs = stmt.executeQuery(wnd.jta1.getSelectedText());
resExec = stmt.execute(wnd.jta1.getSelectedText());
} else {
System.out.println("\"" + wnd.jta1.getText() + "\"");
//rs = stmt.executeQuery(wnd.jta1.getText());
resExec = stmt.execute(wnd.jta1.getText());
}
System.out.println("resExec = " + resExec);
if (resExec == true) {
rs = stmt.getResultSet();
System.out.println("resExec = true, взят rs");
} else {
updCount = stmt.getUpdateCount();
System.out.println("resExec = false, взят updCount = " +
updCount);
}
} catch (SQLException ex1) {
ex1.printStackTrace();
}

Any two requests in a row are not executed.
Only one at a time.
Tried to perform the following query:
"insert into test.client (ClientName, Address1) values ​​('Anton', 'Antonov');
delete from test.client WHERE ClientName = 'Anton' and Address1 = 'Antonov';
select * from test.client; "
Also, do not want to run.

MySQL Connector/J not JDBC 4-compliant? (1 reply)

$
0
0
All newer versions of MySQL Connector are (supposed to be) JDBC 4 compliant. See here:

http://dev.mysql.com/doc/refman/5.5/en/connector-j.html

"MySQL Connector/J is a JDBC Type 4 driver. Different versions are available that are compatible with the JDBC 3.0 and JDBC 4.0 specifications." However, I've checked several of the 5.1.xx versions and they all return

Is JDBC-compliant = false

Strange.

Is it a bug? Is it true? Whichever is the case, there's either a bug in the connector or in the docs.

There's a new JDBC driver installation procedure for the all-new JBoss AS 7 server which causes confusion with application and server developers, see here:

http://community.jboss.org/wiki/DataSourceConfigurationInAS7#comment-7161

This could hinder the overall Java datasource installation process of JBoss AS 7 to some degree.

So what's the matter here? Bug? Docs wrong?

Karsten

Stand-alone java file for JDBC Connectivity not working (1 reply)

$
0
0
Hi All,
I am writing a stand-alone java file (with main() method) in notepad to see JDBC in action. My code is given below :


import java.sql.*;

public class FirstExample {
   
   static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
   static final String DB_URL = "jdbc:mysql://localhost:3306/test";


   static final String USER = "root";
   static final String PASS = "Passw0rd";


	public static void main(String[] args) {
  	 Connection conn = null;
   	 Statement stmt = null;
   		try{
      
      			Class.forName("com.mysql.jdbc.Driver");

      
     			System.out.println("Connecting to database...");
      			conn = DriverManager.getConnection(DB_URL,USER,PASS);

			conn.close();

		}catch(SQLException se){
      
      se.printStackTrace();
   }catch(Exception e){
      
      e.printStackTrace();
   }
  }
}


I have placed the mysql-connector.jar file in the C:\Program Files (x86)\Java\jdk1.6.0_21\bin folder. I have a system variable defined as Path = C:\Program Files (x86)\Java\jdk1.6.0_21\bin
In other words, I have placed the mysql-connector.jar in the same folder that is being pointed to by the Path variable.

Now when I complie this file, it compiles without error, but when I try to run it, I get the exception

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

Can anyone please point out what I need to do? Do I need to place my mysql-connector.jar somewhere else?

I found quite a few posts here that talk about the same issue, but all of them involve some or the other IDE. But I dont want to use an IDE for this.
Please help.
Thanks........

SQLException: Communications link failure / SQLState: 08S01 / Vendor Error Code: 0 (1 reply)

$
0
0
This topic is not new, but the following post for example was closed before anyone could give a good anser:
http://forums.mysql.com/read.php?39,418605,418605#msg-418605

Can anyone give a good solid explanation of how to handle or how to prevent "Communications link failure" SQL exceptions with vender code 0?
Pointing to some reference type of documentation for MySQL Connector/J would also help. The "Documentation" link on this website is a joke: http://dev.mysql.com/usingmysql/java/

I don't have a problem with network links failing. I think this is an error scenario that has to be expected even though it is strange to happen frequently on a machine local TCP/IP connection.

However, the SQL exception "Communications link failure" is especially nasty since I regularly experience the case that an "INSERT" command is actually processed despite throwing the exception. As a consequence, resubmitting the "INSERT" command after reestablishing the connection is an error by itself because the initial "INSERT" was successfully processed.

DriverManager vs. DataSource (1 reply)

$
0
0
Hello,

I am new to JDBC/Java and am in the early planning stages of writing a standalone Java application that will be distributed via JNLP. The application needs to access a MySQL database and there will be multiple users using the application/db simultaneously.

After much Googling it seems that the recommended way to access MySQL is via a DataSource object instead of a DriverManager object. However, based on the examples I found, it seems that DataSource is only for Java applications running on a server like Tomcat. Is this correct? If not, I'd be grateful for pointers on how to properly implement this in a standalone application. I do already have a working example of how to connect via a DriverManager. Thank you.

Problems with SELECT DATABASE() (4 replies)

$
0
0
Hi,
I have a problem when I make this query(SELECT DATABASE())...
if I was logged in a instance database, i have no problem, because the returning result set have the name of the instance inside, and I can get it.

the problem is when I logged in the MySQL server, but not in any instance, in this case my code runs automatically this query (SELECT DATABASE()), and it returns null(because I am not logged in a instance database, but in the server).
The returning resultset have 1 row and 1 col, but when I try to get the name, i have a nullpointerexception.
when I do this:
(String)resultSet.getString(j).trim();
j=1, i dont now how can I retrieve the null information that came in the resultset...?!
The idea is:if the resultset give me no Instance Name...so I am logged in a server!! and when I now it, I don’t need any-more to get the info from the resulset...
I don’t now how to figure out, how i can discover that?!
Can I solve this with a equivalent query, that returns me something diferent for the both cases?
I'm burning my brain...and i have no solution...

Thanks in Advance

Vanishing tables in MySQL 5.5 (4 replies)

$
0
0
Hi folks,

I'm a bit new to MySQL. The steps for my error are as follows:

- I created a new database 'occaisiondb'
create database occaisiondb;

- I switched to that database
use occaisiondb;

- Created a table
create table people_group
    (
       group_name char(50) not null,
       peoplegroup_id int(10) not null
    )

- verified that the table exists
show tables;

- I tried to create an entry in it using Hibernate
SessionFactory sessionFactory = new Configuration()
        .configure() // configures settings from hibernate.cfg.xml
        .buildSessionFactory();
    Session session = sessionFactory.openSession();
	session.beginTransaction();
	session.save( new PeopleGroup("Group 1") );
	session.getTransaction().commit();
	session.close();

- I got the following error:
Hibernate: select max(peoplegroup_id) from people_group
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'occaisiondb.people_group' doesn't exist

- When I went back to the command line and used 'show tables' again, it showed no tables!

Has anyone faced this error before? Please help me out. Thanks

MySQLIntegrityConstraintViolationException Duplicate entry (no replies)

$
0
0
Hi All,

I got this error on my batch system when insert data to table. Before insert, the system deleted data in table:

Log:
--- The error occurred in EmployeeInfo.ibatis.xml.
--- Check the EmployeeInfo.create-InlineParameterMap.
--- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '40008-105' for key 1

This system runs stably for long time. This is the first time this error occur. Does anyone know what's happen?

Please help!

Many Thanks.
Nguyen

lifetime of a resultSet (1 reply)

$
0
0
HI, i am using JDBC and connecting to MySql by the Connecto/J . I am performing an executeQuery and collecting the result in a resultSet .
While iterating through the resultSet , i again create 2 new resultSets form the same Statement object , and iterate throught these new ones . I get the error that resultSet is closed.
Can someone please tell why i get this error and how to overcome it?
THanks.
Here's a part of code:
ResultSet rs=stat.executeQuery(q)

while(rs.next())
{
System.out.println(rs.getInt(1));


Integer id1 = new Integer(rs.getInt(7));
q2 = "Select * from departments where depid="+id1.toString();
rs2 = stat.executeQuery(q2);
while(rs2.next())
{
System.out.println(rs2.getInt(1));

}
Integer id2 = new Integer(rs.getInt(8));
q2 = "Select * from departments where depid="+id2.toString();
ResultSet rs3 = stat.executeQuery(q2);
while(rs3.next())
{
System.out.println(rs3.getInt(1));

}
}

INSERT multiple rows is very slow (2 replies)

$
0
0
Hello

I am trying to insert a large number of rows into a mysql 5.5 database but it is very slow. Same code on POSTGRES and ORACLE is 100s times faster. For mysql I construct my INSERT statements as follows:

INSERT INTO MY_TABLE VALUES ( 1, 1, 'text' ) , ( 2, 1, 'some text') , ....

where the number of values in parenthesis given on every INSERT varies between 100 and 10,000 but with no difference in performance.

Can someone please let me know if there is a way to do this faster?

Stored Proc OUT param help (no replies)

$
0
0
Ok, I need some help. I'm frustrated.

I have two stored procs (among many) that work just fine from the MySQL workbench but when I try to run them via a JDBC CallableStatement I ultimately get a SQLException while trying to register output parameters.

Stored Proc #1 is the one I'm trying to call via JDBC. Stored Proc #2 is included because #1 calls it.

I create a CallableStatement with the following JDBC syntax:
"{call _newSimpleMessage(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"

When I try to register parameter 16 as an output parameter, Connector/J throws an exception complaining that parameter 16 is not an output parameter.
If I swap parameters 16 and 17 the driver still complains.

What am I doing wrong?

Stored Proc #1:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`%` PROCEDURE `_newSimpleMessage`(
IN scriptRunID INT,
IN parentMessageID INT,
IN threadName TEXT,
IN `level` TEXT,
IN creationTime DATETIME,
IN loggingTime DATETIME,
IN sourceClass TEXT,
IN sourceMethod TEXT,
IN sourceFile TEXT,
IN sourceLine INT,
IN stackTrace TEXT,
IN headline TEXT,
IN additionalInfo TEXT,
IN screenshot BLOB,
IN simpleMessageType TEXT,
OUT messageID INT,
OUT simpleMessageID INT
)
BEGIN
CALL _newMessage(
scriptRunID,
parentMessageID,
threadName,
`level`,
creationTime,
loggingTime,
'SimpleMessage',
sourceClass,
sourceMethod,
sourceFile,
sourceLine,
stackTrace,
messageID
);

INSERT INTO SimpleMessage (
`fk_MessageID`,
`Headline`,
`Additional_Information`,
`Screenshot`,
`fk_SimpleMessageTypeID`
) VALUES (
messageID,
headline,
additionalInfo,
screenshot,
(SELECT SimpleMessageTypeID FROM SimpleMessageType WHERE JavaName = SimpleMessageType)
);
SELECT LAST_INSERT_ID() INTO simpleMessageID;
END


Stored Proc #2:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`%` PROCEDURE `_newMessage`(
IN scriptRunID INT,
IN parentMessageID INT,
IN threadName TEXT,
IN `level` TEXT,
IN creationTime DATETIME,
IN loggingTime DATETIME,
IN messageType TEXT,
IN sourceClass TEXT,
IN sourceMethod TEXT,
IN sourceFile TEXT,
IN sourceLine INT,
IN stackTrace TEXT,
OUT messageID INT)
BEGIN
INSERT INTO Message (
`fk_ScriptRunID`,
`ParentMessageID`,
`ThreadName`,
`Level`,
`CreationTime`,
`LoggingTime`,
`fk_MessageTypeID`,
`SourceClass`,
`SourceMethod`,
`SourceFile`,
`SourceLine`,
`StackTrace`
) VALUES (
scriptRunID,
parentMessageID,
threadName,
`level`,
creationTime,
loggingTime,
(SELECT MessageType.MessageTypeID FROM MessageType WHERE MessageType.JavaName = messageType LIMIT 1),
sourceClass,
sourceMethod,
sourceFile,
sourceLine,
stackTrace
);
SELECT LAST_INSERT_ID() INTO messageID;
END

difference of performance when retrieving different column from resultset (3 replies)

$
0
0
Hi,
i am experiencing a very strange issue when i try to load different column from a result set.

I have a table t :
+-----------------------+-------------------------------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+-------------------------------------+------+-----+---------------------+-------+
| sub_id | varchar(20) | NO | PRI | NULL | |
| network_element_id | int(10) unsigned | YES | | NULL | |
| ipv4 | varchar(20) | YES | MUL | NULL | |
| ipv6 | varchar(40) | YES | | NULL | |
| docsis_version | tinyint(4) | YES | | NULL | |
| tier | varchar(30) | YES | | NULL | |
| last_updated_time | timestamp | NO | | 0000-00-00 00:00:00 | |
| last_completed_period | int(10) unsigned | YES | | 0 | |

when i try to retrieve data (sub_id + something else except tier column) from a large resultset i got a very good time:
Load ResultSet took 8 seconds for 892098 rows

But when i try to retrieve data from the tier column ( + sub_id) it could take up to 30 minutes.

Load ResultSet took 1925 seconds for 892098 rows

Both for sub_id and tier I used the method ResultSet.getString(columnName)

Has anyone faced this issue before? Please help me out. Thanks

Java connector over GPRS Network (no replies)

$
0
0
Hi,

I've been using for a while jdbc connector to connect MySQL database over a wired / wireless network. But now I have a project that will run on a GPRS network, I am not sure if there is any reported problem with this connector on this type of network.

I would appreciate if someone can tells me if the connector works fine or if there is any consideration to take care of.


Thanks in advance.

Data mismatch xxx!=xxx (1 reply)

$
0
0
Have two tables t1,t2 from different sources with common data in respective columns t1.c1, t2.c1. The data is mixed alpha numeric.

Running
SELECT t1.c1, t2.c1 from t1.c1 JOIN t2.c1 ON t1.c1 = t2.c1; returns all null for t2.c1.
A query where you select either column on a fixed value (x) will return the correct value. Both columns are set up the same in their respective tables
t1.c1 `Style` varchar(100) COLLATE utf8_bin DEFAULT NULL
t2.c1 `STYLE` varchar(100) COLLATE utf8_bin DEFAULT NULL

So ran a CHAR_LENTH(t(x).c(x)) on both and discovered that the length for a given value is off. One specific result was when both were set to 2307 t1.c1 returned 4 while t2.c1 returned 5. Tried TRIM, CAST, UPPER, LOWER alone and in combinations with no success.

The problem appears to be the STYLE (t2.c1) field Note: c1 not really the right position in actual table;
mysql> SELECT 6_HTS09X.id_6 FROM 6_HTS09X LIMIT 20;
+------+
| id_6 |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
|    5 |
|    6 |
|    7 |
|    8 |
|    9 |
|   10 |
|   11 |
|   12 |
|   13 |
|   14 |
|   15 |
|   16 |
|   17 |
|   18 |
|   19 |
|   20 |
+------+
20 rows in set (0.00 sec)
SELECT 6_HTS09X.id_6,6_HTS09X.STYLE AS 'c.1' FROM 6_HTS09X LIMIT 20;
+------+-----------+
| id_6 | c.1       |
+------+-----------+
     | | 1201
     | | 1303
     | | 1401
     | | 2001
   | 5 | 2001AW
   | 6 | 2001BP
  |  7 | 2001GEO
   | 8 | 2001HA
   | 9 | 2001LA
   |10 | 2001LG
  | 11 | 2001ORG
    |2 | 2001P
    |3 | 2001P
   |14 | 2001SA
 |  15 | 2001STAW
  | 16 | 2001SUN
 |  17 | 2001VIVA
     | | 2007
  | 19 | 2007ORG
     | | 2065
+------+-----------+
20 rows in set (0.00 sec)
[\CODE]
[code]
mysql> SELECT 6_HTS09X.STYLE AS 'c.1' FROM 6_HTS09X LIMIT 20;
+-----------+
| c.1       |
+-----------+
     |
     |
     |
     |
   |01AW
   |01BP
  |001GEO
   |01HA
   |01LA
   |01LG
  |001ORG
    |1P
    |1P
   |01SA
 |2001STAW
  |001SUN
 |2001VIVA
     |
  |007ORG
     |
+-----------+
20 rows in set (0.00 sec)
Using all other fields in any combination are fine. Only when the c1 field is used is there a problem.
I do have an xlxs file for it, the original source document, which I've tried to clean up but maybe missed something.

How should I proceed?
Besides rubbing a lamp, what should I do?

Newer Version returns column name, not alias (1 reply)

$
0
0
I am using MySql with JDBC with all calls from JAVA classes.

I have done my development and testing with MySql version 5.5.10 and all the functionality works as expected.

My production system is MySql version 5.5.47 and my application fails because the metadata returned after a query returns a queries column name not its assigned alias.

Is there a setting that has changed in the newer version? Any suggestions?
---------------------------------------------
Here is my example. Note that columns are selected and then assigned specific aliases using quoted names.

THE QUERY........

select IM_RecNum,
DO_DomainCode AS "IM_SourceCode",
IM_Sequence,
'uploadFileBanner',
'uploadFile',
"uploadImageSize",
DO_ImageHeight as 'uploadNewHeight',
DO_ImageWidth as 'uploadNewWidth',
"uploadThumbSize",
DO_ThumbnailHeight as 'uploadThumbHeight',
DO_ThumbnailWidth as 'uploadThumbWidth'
from domaintable
left join imagetable
ON (DO_DomainCode=IM_SourceCode AND IM_Sequence=0)
where DO_DomainCode="SOMEVALUE"

After the query, I examine the names returned in the metadata for the record set and determine the source tables, etc.

DEVELOPMENTAL MACHINE: MySql version 5.5.10: Win32 x86

return class=com.mysql.jdbc.ResultSet
.. result obtained, get metadata
.. column: 0: table is imagetable and column is IM_RecNum
.. column: 1: table is domaintable and column is IM_SourceCode
.. column: 2: table is imagetable and column is IM_Sequence
.. column: 3: table is and column is uploadFileBanner
.. column: 4: table is and column is uploadFile
.. column: 5: table is and column is uploadImageSize
.. column: 6: table is domaintable and column is uploadNewHeight
.. column: 7: table is domaintable and column is uploadNewWidth
.. column: 8: table is and column is uploadThumbSize
.. column: 9: table is domaintable and column is uploadThumbHeight
.. column: 10: table is domaintable and column is uploadThumbWidth


PRODUCTION MACHINE: MySql version 5.1.47: i686: redhat-linux-gnu

return class=com.mysql.jdbc.JDBC4ResultSet
.. result obtained, get metadata
.. column: 0: table is imagetable and column is IM_RecNum
.. column: 1: table is domaintable and column is DO_DomainCode
.. column: 2: table is imagetable and column is IM_Sequence
.. column: 3: table is and column is uploadFileBanner
.. column: 4: table is and column is uploadFile
.. column: 5: table is and column is uploadImageSize
.. column: 6: table is domaintable and column is DO_ImageHeight
.. column: 7: table is domaintable and column is DO_ImageWidth
.. column: 8: table is and column is uploadThumbSize
.. column: 9: table is domaintable and column is DO_ThumbnailHeight
.. column: 10: table is domaintable and column is DO_ThumbnailWidth

As shown above, with version 5.5.47, the returned names are the original column names, not the aliases.

WORKAROUND!!! ===================

Thanks to advise from my son, it turns out that the problem goes away if the original query uses functions in the selection. In this example, I concatenated
an empty string to strings and added zero to integers:

REVISED QUERY:
select IM_RecNum,
CONCAT(DO_DomainCode,"") AS "IM_SourceCode",
IM_Sequence,
'uploadFileBanner',
'uploadFile',
"uploadImageSize",
DO_ImageHeight+0 as 'uploadNewHeight',
DO_ImageWidth+0 as 'uploadNewWidth',
"uploadThumbSize",
DO_ThumbnailHeight+0 as 'uploadThumbHeight',
DO_ThumbnailWidth+0 as 'uploadThumbWidth'
from domaintable
left join imagetable
ON (DO_DomainCode=IM_SourceCode AND IM_Sequence=0)
where DO_DomainCode=Code AND IM_Sequence=0)
where DO_DomainCode="SOMEVALUE"

REVISED RESULT RETURNED ALIAS NAMES:

class=com.mysql.jdbc.JDBC4ResultSet
.. result obtained, get metadata
.. column: 0: table is imagetable and column is IM_RecNum
.. column: 1: table is and column is IM_SourceCode
.. column: 2: table is imagetable and column is IM_Sequence
.. column: 3: table is and column is uploadFileBanner
.. column: 4: table is and column is uploadFile
.. column: 5: table is and column is uploadImageSize
.. column: 6: table is and column is uploadNewHeight
.. column: 7: table is and column is uploadNewWidth
.. column: 8: table is and column is uploadThumbSize
.. column: 9: table is and column is uploadThumbHeight
.. column: 10: table is and column is uploadThumbWidth

However, I have almost 200 queries that use aliases and there may be some nasty
situations that may complicate any "simple" solution (e.g. what happens when the value is null?).

So, I really would like to understand the root cause.

IS IT A BUG???? ===============================

If this seems to be a bug, I will go through the exercise of preparing test data and a simple JAVA class, but I am hopeful that there is a setting that I can change.

Thanks in advance....

David

What gets cached when cachePrepStmts=true? (1 reply)

$
0
0
Hi,
I use connector option cachePrepStmts=true.
I have doubts about how to fine-tune prepStmtCacheSize in cases when I know that only very few statements need to be cached.
The doubts are about:

- When I run an insert that has to return the auto-generated columns (I use Spring, concretely SimpleJdbcInsert.executeAndReturnKey(), does the connector have native support for this, or the only possible way is that Spring issues a separate SELECT LAST_INSERT_ID()? (Note: Looking to the code, Spring checks for native support of the underlaying connector for returning auto-generated keys, but I don't know what's the response of mysql connector, as it's a bit difficult to debug. If the connector has native support, does it in fact issue a separate query (like the previous one) or it is part of the same insert statement? The thing is, either if Spring must issue a separate select or if the connector itself issues a separate query, then I must must have this into account when caching inserts, as, if the separate query is a prepared statement, then it will need to be cached too (so, 2 entries per insert). Does anybody know, in the case of native support with separate query, if this query is prepared or not?

- According to the docs, prepared-statement cache caches several things:
1) The parsing stage of PreparedStatements of client-side prepared statements (client-side only)
2) The "check" for suitability of server-side prepared statements
3) The server-side prepared statements themselves (server-side only)
My doubt is: does every of these things use a cache entry (so, two entries per prepared statement) or everything is cached within the same entry? If they are separate entries, then, if I want to cache at most one prepared statement, I should configure prepStmtCacheSize=2 or I wouldn't have space for all the info. prepStmtCacheSize doc talks about the number of prepared statements that can be cached, so I guess it's 1 for all the info of 1 prepared statement, but I'd like to make sure.

Thanks,

Juan

Connection link failure (no replies)

$
0
0
Hey.

I am working on a project with some friends, and we are making a java program in eclipse linked up to a mysql server. I am running on a windows vista and the other guys on windows7. Whenever I try to start my program i get an error: Connection link failure. It is working as supposed on my friends computers.

Do anyone here know about any problems with eclipse, java mysql connector or something? Please help me out here : P

Best regards : )

java.net.SocketException: No buffer space available (maximum connections reached?) (5 replies)

$
0
0
Hi all!

I get an error when trying to write to the database a new record using the stored procedure.
Such records be written quite a lot per second: 120-150.

The table structure is as follows:
v bigint(20)
id bigint(20) PK
segmentId int(11)
socialId varchar(25)
fullName varchar(50)
photoUrl tinytext
registrationTime datetime
level int(11)
sectorName varchar(50)
x int(11)
y int(11)
caravanSpeed double
occupantUserId bigint(20)
sectorSkinTypeId bigint(20)
isNotHaveExperience tinyint(1)

Table is indexed by (id), (x,y) and (level).

Here is the text of exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor11.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:346)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2334)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor7.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.test.WorkWithDB.getConn(WorkWithDB.java:74)
at com.test.WorkWithDB.saveUser(WorkWithDB.java:100)
at com.test.RunThread1_1.run(RunThread1_1.java:39)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:295)
... 17 more

I think I need to increase the innodb_buffer_pool_size value from 78M to higher value.

Do I think right?

I already synchronized the recording of one entry by the object in my java-code.

When the system is "slows down" (slows due to other programs works with HDD), the write speed is reduced, and no error occurs (45-80 entries per second). Errors occur only when a sufficiently rapid writes of entries into the database (120-150 entries per second).
Viewing all 884 articles
Browse latest View live


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