Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26525 > unrolled thread

Bash script not working as commandline MySQL JDBC

Started byRVic <rvince99@hotmail.com>
First post2013-11-17 08:40 -0800
Last post2013-11-17 16:09 -0600
Articles 8 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Bash script not working as commandline MySQL JDBC RVic <rvince99@hotmail.com> - 2013-11-17 08:40 -0800
    Re: Bash script not working as commandline MySQL JDBC markspace <markspace@nospam.nospam> - 2013-11-17 08:56 -0800
    Re: Bash script not working as commandline MySQL JDBC RVic <rvince99@hotmail.com> - 2013-11-17 09:16 -0800
      Re: Bash script not working as commandline MySQL JDBC Robert Klemme <shortcutter@googlemail.com> - 2013-11-17 20:01 +0100
      Re: Bash script not working as commandline MySQL JDBC Steven Simpson <ss@domain.invalid> - 2013-11-17 19:34 +0000
    Re: Bash script not working as commandline MySQL JDBC RVic <rvince99@hotmail.com> - 2013-11-17 12:38 -0800
      Re: Bash script not working as commandline MySQL JDBC Robert Klemme <shortcutter@googlemail.com> - 2013-11-17 22:06 +0100
      Re: Bash script not working as commandline MySQL JDBC Mike Amling <mamling@chaff.us> - 2013-11-17 16:09 -0600

#26525 — Bash script not working as commandline MySQL JDBC

FromRVic <rvince99@hotmail.com>
Date2013-11-17 08:40 -0800
SubjectBash script not working as commandline MySQL JDBC
Message-ID<7f1a4290-6ce6-4673-a411-62dbb326ef99@googlegroups.com>
I'm quite at a loss here.I'm using JDBC to connect to a MySQL database. If I type the command in from the command line (passing it the parameters for db name and user / password) it runs fine:

exec java -classpath .:$CLASSPATH:/home/user/ggrip/upserver/mysql-connector-java-5.1.26-bin.jar:/home/user/ggrip/upserver/GGUser.jar GG.GGServer "127.0.0.1:3306" ggripserver1 ggripv2 root root

However, if I create a bash file of the identical command and execute it, I'm getting:
user@Mint15-32 ~/ggrip/upserver $ echo $SHELL
/bin/bash
user@Mint15-32 ~/ggrip/upserver $ ./ggrip.sh
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)Error creating connection pool!
java.sql.SQLException: Can't connect with: com.mysql.jdbc.Driver to jdbc:mysql://127.0.0.1:3306/ggripv2 root root

I just don't get it?

[toc] | [next] | [standalone]


#26526

Frommarkspace <markspace@nospam.nospam>
Date2013-11-17 08:56 -0800
Message-ID<l6asf6$9kn$1@dont-email.me>
In reply to#26525
On 11/17/2013 8:40 AM, RVic wrote:
> I'm quite at a loss here.I'm using JDBC to connect to a MySQL
> database. If I type the command in from the command line (passing it
> the parameters for db name and user / password) it runs fine:
>
> exec java -classpath
> .:$CLASSPATH:/home/user/ggrip/upserver/mysql-connector-java-5.1.26-bin.jar:/home/user/ggrip/upserver/GGUser.jar
> GG.GGServer "127.0.0.1:3306" ggripserver1 ggripv2 root root
>
> However, if I create a bash file of the identical command and execute
> it, I'm getting: user@Mint15-32 ~/ggrip/upserver $ echo $SHELL
> /bin/bash user@Mint15-32 ~/ggrip/upserver $ ./ggrip.sh
> java.sql.SQLException: Access denied for user 'root'@'localhost'
> (using password: YES)Error creating connection pool!
> java.sql.SQLException: Can't connect with: com.mysql.jdbc.Driver to
> jdbc:mysql://127.0.0.1:3306/ggripv2 root root
>
> I just don't get it?
>



My guesses are 1) you have a typo, since you didn't show us the actual 
script, or 2) you there's a shell or variable expansion that's tripping 
you up.

Look up bash shell debugging, try a few things there, and let us know 
when you've found a few things more.  Make sure the command is executing 
exactly as you expect, not some close but different facsimile.

[toc] | [prev] | [next] | [standalone]


#26527

FromRVic <rvince99@hotmail.com>
Date2013-11-17 09:16 -0800
Message-ID<82164d93-e023-4b3e-82a7-cf7247a1e0e1@googlegroups.com>
In reply to#26525
The script is the same as the command itself (in fact, when I run the command from the command line, I simply copy it from the text of the script and paste it into the terminal window):

ggrip.sh
--------
exec java -classpath .:$CLASSPATH:/home/user/ggrip/upserver/mysql-connector-java-5.1.26-bin.jar:/home/user/ggrip/upserver/GGUser.jar GG.GGServer "127.0.0.1:3306" ggripserver1 ggripv2 root root 

[toc] | [prev] | [next] | [standalone]


#26528

FromRobert Klemme <shortcutter@googlemail.com>
Date2013-11-17 20:01 +0100
Message-ID<besi50FhhooU1@mid.individual.net>
In reply to#26527
On 17.11.2013 18:16, RVic wrote:
> The script is the same as the command itself (in fact, when I run the
> command from the command line, I simply copy it from the text of the
> script and paste it into the terminal window):
>
> ggrip.sh -------- exec java -classpath
> .:$CLASSPATH:/home/user/ggrip/upserver/mysql-connector-java-5.1.26-bin.jar:/home/user/ggrip/upserver/GGUser.jar
> GG.GGServer "127.0.0.1:3306" ggripserver1 ggripv2 root root

I'm not assuming that it's related to the error but you should quote 
your classpath properly.

As Mark said: use shell debugging (insert "set -x" at top of script and 
also in the interactive shell).

Also, "type java" might give you an idea whether "java" is an alias on 
your command prompt.

Cheers

	robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#26529

FromSteven Simpson <ss@domain.invalid>
Date2013-11-17 19:34 +0000
Message-ID<bainla-a34.ln1@s.simpson148.btinternet.com>
In reply to#26527
On 17/11/13 17:16, RVic wrote:
> ggrip.sh
> --------
> exec java -classpath .:$CLASSPATH:/home/user/ggrip/upserver/mysql-connector-java-5.1.26-bin.jar:/home/user/ggrip/upserver/GGUser.jar GG.GGServer "127.0.0.1:3306" ggripserver1 ggripv2 root root

Is CLASSPATH exported?  Whether it is won't affect the direct command, 
but it will affect what the script receives.

-- 
ss at comp dot lancs dot ac dot uk

[toc] | [prev] | [next] | [standalone]


#26530

FromRVic <rvince99@hotmail.com>
Date2013-11-17 12:38 -0800
Message-ID<7a51917c-ccd4-4293-abf7-4d42dce215b5@googlegroups.com>
In reply to#26525
Gentleman,

Thank each of you for your help. I got it solved by simply putting a semicolon at the end of the lone statement in the script!

[toc] | [prev] | [next] | [standalone]


#26531

FromRobert Klemme <shortcutter@googlemail.com>
Date2013-11-17 22:06 +0100
Message-ID<bespfmFj5hfU1@mid.individual.net>
In reply to#26530
On 17.11.2013 21:38, RVic wrote:
> Gentleman,
>
> Thank each of you for your help. I got it solved by simply putting a
> semicolon at the end of the lone statement in the script!

Huh?  I don't see how that can be.  The semicolon will just terminate 
the statement and won't change anything at all about the command line 
sent to java.  I am more inclined to believe the reason Seven put forward.

Cheers

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#26532

FromMike Amling <mamling@chaff.us>
Date2013-11-17 16:09 -0600
Message-ID<best4mFjvehU1@mid.individual.net>
In reply to#26530
On 11/17/13 2:38 PM, RVic wrote:
> Gentleman,
>
> Thank each of you for your help. I got it solved by simply putting a semicolon at the end of the lone statement in the script!

I've seen something very similar when using Cygwin. The editor, vim, 
knew it was running on Windows and provided a line ending of CRLF. 
Cygwin read the script and treated the CR as part of the last word on 
the command line. Putting a semicolon at the end protected the command's 
last word from being unintentionally extended.

Mike Amling
--
Just when we secure for ourselves the benefits of the rule of law, 
Murphy shows up.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web