2

I am having a problem. I have a query that checks one database table and updates another database table. I am using MySQL 5.1

UPDATE dldd.temp,test.temp 
SET  test.temp.name = dldd.temp.word
WHERE dldd.temp.id = test.temp.id

this is my SQL statement that is working fine. Now I want to execute this statement using Java PreparedStatement . The problem is I don't know how to write the Connection String to select two database i.e

"jdbc:mysql://localhost:3306/"+dbname+"?characterEncoding=UTF-8"

What should come in place of dbname. Can I select multiple db there.

1 Answer 1

2

Have a look at http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html.

If the database is not specified, the connection is made with no default database. In this case, either call the setCatalog() method on the Connection instance, or fully specify table names using the database name (that is, SELECT dbname.tablename.colname FROM dbname.tablename...) in your SQL. Opening a connection without specifying the database to use is generally only useful when building tools that work with multiple databases, such as GUI database managers.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this solves the problem. I have not specified the database there and it's working, but the user should have all PRIVILEGES on the MySQl server to connect this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.