LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-26-2009, 10:36 AM   #1
js_pierce
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Rep: Reputation: 0
mysql connector/j problems with query syntax


I pretty new to all of these technologies. I am trying to get a java program to connect to mysql using the mysql connector/j package. I have been able to install mysql under Windows and compile a test java program that will connect to mysql and add and modify records. I can not do the same on my linux setup.

On linux I can access mysql from the command line, add and modify databases. When I compile one of the simple java test programs that worked under windows things will not connect.

The programs that I have tried all have lines similar to the following


Class.forName("com.mysql.jdbc.Driver").newInstance();


con = DriverManager.getConnection("jdbc:mysql:///test",
"root", "secret");

I think that I have set the CLASSPATH variable correctly because I the Class.forName executes successfully.

On the .getConnection command I get an sql exception error complaining about my syntax around the '???????????????'.

When I look at the sql logfile I see that a connectino query has be issued that includes some lines of '???????????????' in it.

I have installed different versions of the connector software with the same results.

Can someone help?

Thanks

Stan

Last edited by js_pierce; 04-26-2009 at 10:39 AM.
 
Old 04-26-2009, 06:30 PM   #2
soleilarw
Member
 
Registered: Apr 2009
Posts: 107

Rep: Reputation: 19
Do you have the mysql connector/j package also installed on Linux? This rather seems like there's something missing to support some of your scripting functions.

Linux Archive

Last edited by soleilarw; 06-18-2009 at 04:41 AM.
 
Old 04-26-2009, 07:10 PM   #3
js_pierce
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by soleilarw View Post
Do you have the mysql connector/j package also installed on Linux? This rather seems like there's something missing to support some of your scripting functions.

I have the total package installed on linux debian lenny. I am trying to execute this java program on the same machine that I have the MySQL package installed. All host names are Localhost or IP address 127.0.0.1
 
Old 04-26-2009, 07:32 PM   #4
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Your syntax looks rather cheesy. I have never needed the newInstance() method to initialize the driver. Neither do I see any declaration of "con" (Connection con).
 
Old 04-27-2009, 06:54 AM   #5
js_pierce
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jay73 View Post
Your syntax looks rather cheesy. I have never needed the newInstance() method to initialize the driver. Neither do I see any declaration of "con" (Connection con).


I was giving the lines that referenced the connector/j code. I have listed the whole test program below. This program and similar programs were listed online as test examples for the jdbc connector/j code. As I said earlier, this code seems to work find in a totally Windows environmemt - both when mysql is on localhost and when on a server.

I feel that there is something missing in the setup for linux. However the only instruction for the setup is to update the CLASSPATH variable with the .jar file from the setup. When this is not done I get and error on the Class.forName line, so I think that I have done this correctly.

Thanks






import java.sql.*;

public class TestMysql {

public static void main(String args[]) {
Connection conn = null;



/* Test loading driver */
String driver = "com.mysql.jdbc.Driver";

System.out.println( "=> loading driver:" );
Class.forName( driver );
System.out.println( "OK" );

/* Test the connection */
String url = "jdbc:mysql://localhost:3306/test";

System.out.println( "=> connecting:" );
conn = java.sql.DriverManager.getConnection( url, "root", "rootpw" );
System.out.println( "OK" );


Statement s = conn.createStatement ();
int count;
s.executeUpdate ("DROP TABLE IF EXISTS animal");
System.out.println( "Drop" );
s.executeUpdate (
"CREATE TABLE animal ("
+ "id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+ "PRIMARY KEY (id),"
+ "name CHxAR(40), category CHAR(40))");
System.out.println( "create" );
count = s.executeUpdate (
"INSERT INTO animal (name, category)"
+ " VALUES"
+ "('snake', 'reptile'),"
+ "('frog', 'amphibian'),"
+ "('tuna', 'fish'),"
+ "('racoon', 'mammal')");
System.out.println( "insert" );
s.close ();
System.out.println( "close" );
System.out.println (count + " rows were inserted");


}
}
}
 
  


Reply

Tags
mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql and mysql java connector, connection refused arubin Slackware 3 03-29-2008 02:41 AM
interesting MySQL query/view query :s mjh Programming 3 03-25-2008 08:30 AM
PHP/MySQL - Proper syntax for using alphabetical variables in a query? win32sux Programming 3 03-10-2008 07:37 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 07:36 PM
A Simple MySQL Query Question (I have Bad Syntax) bpk General 1 12-02-2003 10:04 PM


All times are GMT -5. The time now is 11:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration