Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Running a java code in CentOS server to connect mysql

My code is -

String server = "", url = "", password = "", user = "", databasename = "";
    Connection con = null;
    try {
        server = "xxx.xxx.xxx.xxx";
        databasename = "xx";
        user = "user";
        password = "pass";
        Class.forName("com.mysql.jdbc.Driver");
        url = "jdbc:mysql://" + server + "/" + databasename + "";
        con = DriverManager.getConnection(url, user, password);
        System.out.println(server + " Database connection established");
        System.out.println(con);
    } catch (Exception e) {
        System.out.println("***************connection failed********************");
        e.printStackTrace();
    }

My database is running in same server.

I am running this code in my local system and other server for same database and its running fine but its not running on same server where my database available. I am getting this exception -

    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 '??????????????' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1027)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3361)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3295)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1852)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1975)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2470)
   at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1669)
   at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3336)
   at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1979)
   at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
   at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:287)
   at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
   at java.sql.DriverManager.getConnection(libgcj.so.10)
   at java.sql.DriverManager.getConnection(libgcj.so.10)
   at testthread.ConnectionFactory.getConnection(ConnectionFactory.java:28)
   at testthread.ConnectionFactory.main(ConnectionFactory.java:39)

is any one help me what is the problem.

share|improve this question
    
what SQL-query are you running? Would you post it? –  triclosan Jul 20 '12 at 9:57
    
Can't help, because the code that's causing the problem isn't shown. Looks like bad SQL syntax to me. Go to the line that the stack trace tells you is the source of the problem and take a look. –  duffymo Jul 20 '12 at 9:57
    
@Triclosan: Not running any query just connection to mysql database which is running in same server. –  Khoyendra Pande Jul 20 '12 at 10:00
    
@Duffmo: con = DriverManager.getConnection(url, user, password); at this line getting this exception. –  Khoyendra Pande Jul 20 '12 at 10:02
    
` jdbc:mysql://localhost:3306/` where did you mentioned the port no ??? Is the server String contains port no ???? Also change your url to --> ` url = "jdbc:mysql://" + server + "/" + databasename; ` JDBC CONNECTION did you use any ?????????????? in your sql Query ??? –  Amith Jul 20 '12 at 10:07

1 Answer 1

This problem seems to be very similar to the following: Stumped SQL Exception for JDBC

Try checking character set configuration/data in your local database server

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.