简体   繁体   中英

Connection String to MySQL Temporary Table in Java

I am trying to create a temporary table in memory in order to store some data in it and use it within the application life time..

I am trying to do something as follows:

StringBuilder sb = new StringBuilder();
sb.append("CREATE TEMPORARY TABLE XmlItems ENGINE=MEMORY AS (");
// Continue with columns definitions
sb.append(")");

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/");
Statement stat = conn.createStatement();
stat.executeUpdate(sb.toString());

But the following exception is being thrown:

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

I'm guessing it has to do something with the connection string..

Any ideas?

You haven't provided schema name in the jdbc connection URL. Try after adding schema name at the end of URL.

jdbc:mysql://localhost:3306/myschema

检查以确保在这种情况下(mysql)该数据库已启动/正在运行,尽管您尚未添加要使用的数据库名称而不是"jdbc:mysql://localhost:3306/" ,但连接String看起来还是不错的使用"jdbc:mysql://localhost:3306/databae_name"

The connection string has to contain a database schema to connect to.

DriverManager.getConnection("jdbc:mysql://localhost:3306/myTestDB");

Also, make sure that MySQL is actually running. "Communications link failure" sounds more like the connection to port 3306 is refused.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM