Home > database >  Use pipe JDBC access mysql problems
Use pipe JDBC access mysql problems

Time:09-28

1, does the JDBC support under Linux use pipe access mysql
2, use the same Java code under win10 different url test read 5 million rows, named pipes (named pipe) to 30-50% slower than TCP, associated documentation and system configuration, I'd like to know what are the influence of configuration, is how to influence
3, the extraction of the JDBC url socketFactory com. Mysql. JDBC. NamedPipeSocketFactory and com. Mysql. JDBC. StandardSocketFactory respectively is what kind of work mechanism, how to influence reading efficiency

The test code:
The CREATE TABLE ` tt ` (
` pid ` int (11) the DEFAULT NULL,
` val ` varchar (255) the DEFAULT NULL,
` pdate ` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

import java.sql.*;
import java.util.Date;

Public class JavaMysqlSelectExample {
Public static void main (String [] args) {
Try {
//create our mysql database connection
String myDriver="org. GJT. Mm. Mysql. Driver".
String myUrl=null;
String query;
If (1==2) {
MyUrl="JDBC: mysql://localhost/mydb? UseCursorFetch=true ";
Query="SELECT * FROM test";
} else if (1==1) {
MyUrl="JDBC: mysql://127.0.0.1:3306/mydb? SocketFactory=com. Mysql. JDBC. StandardSocketFactory& UseCursorFetch=true ";
//myUrl="JDBC: mysql://127.0.0.1:3306/mydb? SocketFactory=com. Mysql. JDBC. NamedPipeSocketFactory& UseCursorFetch=true ";
//myUrl="JDBC: mysql://address=(protocol=pipe)/mydb? UseCursorFetch=true ";
//myUrl="JDBC: mysql://address=(TCP) protocol=(host=localhost) (port=3306)/mydb? UseCursorFetch=true ";
Query="SELECT * FROM tt";
}
Class.forname (myDriver);
The Connection conn=DriverManager. GetConnection (myUrl, "root", "root");

Export (conn, query);
} the catch (Exception e) {
System. Err. Println (" Got an exception! ");
System. Err. Println (um participant etMessage ());
}
}

Public static void export (Connection conn, String query) {
Try {
The Date dStart=new Date ();
.//com. Mysql. JDBC Statement st=(. Com. Mysql. JDBC Statement) conn. CreateStatement ();
//the ResultSet rs=st. executeQuery (query);
//st. enableStreamingResults ();
The Statement st=conn. CreateStatement (ResultSet. TYPE_FORWARD_ONLY,
The ResultSet. CONCUR_READ_ONLY);
St. setFetchSize (Integer. MIN_VALUE);
St. setFetchDirection (ResultSet. FETCH_REVERSE);
The ResultSet rs=st. executeQuery (query);

Int nCount=0;
While (rs), next ()) {
Int id=rs. Get int (" pid ");
String sVal=rs. Get String (" val ");
//Date dateCreated=rs. GetDate (" pdate ");

If (nCount %==0 2000) {
//System. Out. Println (" nCount="+ nCount);
}
NCount++;
}
St. close ();
The Date dEnd=new Date ();
Long diff=dEnd. GetTime () - dStart. GetTime ();
System. The out. Println (" duration="+" nCount="+ + diff nCount);
} the catch (Exception e) {
System. Err. Println (" Got an exception! ");
System. Err. Println (um participant etMessage ());
}
}
}
  • Related