MySQL Forums
Forum List  »  MySQL Administrator

Need some help establishing connection to mysql database with java
Posted by: Darin Cyr
Date: December 26, 2008 12:26AM

HI,
I'm trying to get java to connect to a mysql database and I'm getting an error that looks like the driver is sending a bad string to mysql server.

Can anyone tell me what's going on here and how to fix it?
Thanks!!!

Details:
OS: ubuntu 8.10
MySQL server: 5.0.67
java version 1.6.0_0
driver: mysql-connector-java-5.1.6.jar
IDE: Eclipse

Code:
import java.sql.*;

public class Connect
{
public static void main(String args[])
{
try
{
//register the driver
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("driver registered");

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/form?" +
"user=root&password=master");
System.out.println("connection established");
} // try
catch(SQLException ex)
{
System.out.println(ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} // end catch
}// end main
} // end class Connection



Error Message from terminal:

driver registered
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 '????????????????' at line 1
SQLState: 42000
VendorError: 1064


Error message from mysql server log:
41 Connect root@localhost on form
41 Query /* mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} ) */SHOW VARIABLES WHERE Variable_name ='language' OR Variable_name = 'net_write_timeout' OR Variable_name = 'interactive_timeout' OR Variable_name = 'wait_timeout' OR Variable_name = 'character_set_client' OR Variable_name = 'character_set_connection' OR Variable_name = 'character_set' OR Variable_name = 'character_set_server' OR Variable_name = 'tx_isolation' OR Variable_name = 'transaction_isolation' OR Variable_name = 'character_set_results' OR Variable_name = 'timezone' OR Variable_name = 'time_zone' OR Variable_name = 'system_time_zone' OR Variable_name = 'lower_case_table_names' OR Variable_name = 'max_allowed_packet' OR Variable_name = 'net_buffer_length' OR Variable_name = 'sql_mode' OR Variable_name = 'query_cache_type' OR Variable_name = 'query_cache_size' OR Variable_name = 'init_connect'
41 Query SHOW COLLATION
41 Query ????????????????

Options: ReplyQuote


Subject
Written By
Posted
Need some help establishing connection to mysql database with java
December 26, 2008 12:26AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.