aspose file tools*
The moose likes JDBC and the fly likes Java: connecting to mysql [Unsolved] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java: connecting to mysql [Unsolved]" Watch "Java: connecting to mysql [Unsolved]" New topic
Author

Java: connecting to mysql [Unsolved]

Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
I earlier tried to connect to mysql from JSP it failed so now I am trying to connect from Java but here is the error it comes up with...



Here is the program ...

[ January 03, 2006: Message edited by: Raghavan Chockalingam ]

Raghavan
SCJP 6
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by Raghavan Chockalingam:
I earlier tried to connect to mysql from JSP it failed so now I am trying to connect from Java but here is the error it comes up with...



Here is the program ...


Why don't you believe the compiler when it tells you what you've done wrong?

Look at the two lines it's complaining about:

createtable.java:8: cannot find symbol
symbol : method DriverManager(java.lang.String)
location: class CreateTable
con = DriverManager("jdbc:mysql://localhost/new_db?user=root&pass
word=demoPassword");

You forgot to include the static method call:


^
createtable.java:9: cannot find symbol
symbol : method createConnection()
location: interface java.sql.Connection
Statement stmt = con.createConnection();

There is no create connection method on java.sql.Connection. However, there is a createStatement method:



Read the error messages you get more carefully.


%
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
Sorry...I was tired in the morning, I did not have a close look at it...I have solved that problem now. The file compiles properly now but when it runs, it comes up with this error..


Here is the file...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Exception in thread "main" java.lang.UnsupportedClassVersionError: CreateTable (Unsupported major.minor version 49.0)

This error means that you have compiled your source code with Java 1.5, and now you are trying to run it on an older version of Java (1.4 or older).

Do you have multiple versions of the Java runtime environment installed? Make sure you compile and run your source code with the same version.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
As you said, I have two versions now, jdk 1.4.2 and jdk 1.5.0. Right now, the program is compiled in javac of 1.5.0 and I so far think that I am trying to run using java in 1.5.0

How can it use different version of java when i use javac of 1.5.0.
Here is the list of environment variables...

[ January 03, 2006: Message edited by: Raghavan Chockalingam ]
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
Recently when I tested the verions of java and javac, I found that java.exe's version is 1.4.2 and javac.exe's version is 1.5.0. I do not have a clue why this happened and I am now wondering how to make java to point to 1.5.0....
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

Raghavan,
It is getting Java 1.4 from somewhere on the PATH.

It is likely that another application is pointing to Java 1.4. You can search for java.exe one the hard drive to try and determine which one. Note that you also have Java 1.3 on that path.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You probably have a JRE first on your system path. If you had 'which' installed you could diagnose the problem easily. I'd edit the path and pace a single java entry first and remove the rest.
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
guys, I have put new path in place but still java.exe points to 1.4.2

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

in a command prompt, type this in:


then test java -version
Hopefully (by placing it first) you will make sure it uses the version you want in preference to anything else lying around.

Dave

[EDIT - I just realised you had your '\' slashes the wrong way.]
[ January 04, 2006: Message edited by: David O'Meara ]
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
Pls look at the post below as I taking this as a separate issue
http://www.coderanch.com/t/401934/java/java/java-javac-exes-running-different
Thanks for your support...
s wei
Greenhorn

Joined: Jan 04, 2006
Posts: 2
Originally posted by Raghavan Chockalingam:
I earlier tried to connect to mysql from JSP it failed so now I am trying to connect from Java but here is the error it comes up with...



Here is the program ...


[ January 03, 2006: Message edited by: Raghavan Chockalingam ]
s wei
Greenhorn

Joined: Jan 04, 2006
Posts: 2
Originally posted by s wei:

Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
You already had this same problem in this very thread?!? There is no method called createConnection in java.sql.Connection. Based on the rest of your code you mean to use createStatement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java: connecting to mysql [Unsolved]
 
Similar Threads
noob question about jdbc
First Bean with Database
Java won't send SQL query
My java and javac exes are running on different versions...[unsolved]
Cannot find symbol