• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java: connecting to mysql [Unsolved]

 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34074
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys, I have put new path in place but still java.exe points to 1.4.2

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by s wei:

 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic