Re: Compiling with mysql

ezer <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
A simple example


import java.sql.*;

public class MysqlConnect{
  public static void main(String[] args) {
    System.out.println("MySQL Connect Example.");
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "myDatabase";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password = "root";
    try {
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url+dbName,userName,password);
      System.out.println("Connected to the database");
      conn.close();
      System.out.println("Disconnected from database");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}


in ubuntu i compile:
javac MysqlConnect.java

execution:
java MysqlConnect

output:
MySQL Connect Example.
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:936)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
   at
com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
   at
com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
   at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
   at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
   at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
   at java.sql.DriverManager.getConnection(libgcj.so.90)
   at java.sql.DriverManager.getConnection(libgcj.so.90)
   at MysqlConnect.main(MysqlConnect.java:14)


$ java -version
java version "1.5.0"
gij (GNU libgcj) version 4.3.1

Please any idea ?


ezer wrote:
> 
> Now i am trying diferent. i generated an .o file with mysql driver and get
> an error, that error was the same when i try to run the applicatyion using
> the java from gcj without generating native code.
> 
> java -jar Myapp.jar
> 
> 
> 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
> 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:936)
>    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
>    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
>    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
>    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
>    at
> com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
>    at
> com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
>    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
>    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
>    at
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at xx.yy.dao.DAO.getConnection(DAO.java:103)
> 
> 
> $ java -version
> java version "1.5.0"
> gij (GNU libgcj) version 4.3.1
> 
> 
> The same execution with the sam jar under win xp runs fine
> 
> 
> 
> ezer wrote:
>> 
>> I am triyng for a week to compile a project using mysql. I get all kind
>> of errors. 
>> i used mysql-connector-java-3.1.14-bin.jar,
>> mysql-connector-java-5.1.6-bin.jar and mysql-connector-java-5.1.6-bin.jar
>> I use something like that gcj --main=MyMainClass -o MyExec MyJar.jar
>> The MyJar i tryed to generate with all the java versions, 1.4, 15 and 1.6
>> 
>> I searched the net for info but i couldnt find anything...
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Compiling-with-mysql-tp19092090p19271800.html
Sent from the gcc - java mailing list archive at Nabble.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.