This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Changing the output of this code  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,

I have read many and many pages, but I still need help to make the number combinations created by the followindg code be stored in a specific column that exists in a MySQL's table (MySQL database named `database`, table called `numbers`, column `combinations`).

I know I have to create a connection to the database, but I don't know the correct place of the code to write, and I also don't know how to make the temporary arrays to be stored in the column `combinations`.

So, please, I am asking your help to change the output of this code, so that the column `combinations` be filled with the combinations generated.

Regards,

John


 
Sheriff
Posts: 5022
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I would change this to creating a string and then posting that:

 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Knute Snortum,

Thank you very much for your reply.

Could you please help me write the code to post the string sb to the column `combinations" ?

Although I have tryied a few times, I am not able to write correctly the method postToDb.

MySQL database named `database`, table called `numbers`, column `combinations`.

Regards,

John
 
author & internet detective
Marshal
Posts: 38503
653
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joao Valencio Silva wrote:Although I have tryied a few times, I am not able to write correctly the method postToDb.


Show what you have so far. We can then make improvements and get you closer to a solution.

There currently no JDBC code at all in the thread, so we'd be helping you from scratch right now!
 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Jeanne Boyarsky,

So far, I have the following code. And I need that the temporary arrays (number combinations) be stored into column `combinations`.

Regards,

John

 
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't want to insert the string "sb" into that database column. If you execute that code, that is what will happen. I'm surprised you didn't try it -- or did you try it and just not tell us what happened?

Anyway...


 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,

I still need some help with the following code.

The code is not able to write the combinations into the file "combinations.txt".

Any help will be appreciated.

Regards,

John


 
Paul Clapham
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joao Valencio Silva wrote:The code is not able to write the combinations into the file "combinations.txt".



How do you know that? And why do you think that it should have written anything into the file?

It would help if you read our FAQ article TellTheDetails (<-- follow that link).
 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Paul Clapham,

How did I know that?

Easy...

Hit the "Run Botton" and the file "combinations.txt" is created, but it has only one line with something that is not a number combination.

And it is also easy for anyone to know...  copy and paste this code and run it.

Looks like the problem is at line 53



Regards,

John
 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I sayd before, I think that the problem is at line 53.

Fell free to copy, paste and run the code.

Regards,

John

 
Paul Clapham
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joao Valencio Silva wrote:Looks like the problem is at line 53



Yes, it is. That isn't even valid Java code, so running it doesn't make any sense until you've fixed the compiler errors.

you should be able to see the compiler errors, too.
 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Paul Clapham,

The error message is:

        Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method println(boolean) in the type PrintWriter is not applicable for the arguments (void)
Syntax error on token "int", delete this token

at Combinations.saveCombinations(Combinations.java:53)
at Combinations.main(Combinations.java:70)

If you had copy-pasted and run this code, you would see the same error message. You may copy-paste and run this code if you will.

Of course I have to fix the complier erros, and that's the reason why I am here asking the help of experts (It does not make any sense to post this message if I know how to solve the problem).

Regards,

John
 
Joao Valencio Silva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Paul Clapham and other experts,

Do you have any sugestions of what should be written at line 53 in order to make the code run correctly?

Any help will be appreciated.

Regards,

John

 
Saloon Keeper
Posts: 2020
273
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joao Valencio Silva wrote:Do you have any sugestions of what should be written at line 53 in order to make the code run correctly?


Well, you can make your program run by commenting-out line 53, but that it probably not what you want.

What exactly are you trying to print to the file?  Is it the information being printed here:
 
Paul Clapham
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joao Valencio Silva wrote:If you had copy-pasted and run this code, you would see the same error message.



Indeed. I could start up Eclipse, copy the code, create a place to paste it, and see the error message.

Or you could just tell me the error message. That would be faster for both of us. In future please tell us the details and don't force us to do a lot of work to find out your problem.
 
Knute Snortum
Sheriff
Posts: 5022
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So as you suspected, this line is the problem.  First of all it won't compile.  Don't try to run a file that won't compile.  So what's the error message?  You stated

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method println(boolean) in the type PrintWriter is not applicable for the arguments (void)
Syntax error on token "int", delete this token 


So let's take the first message, "The method println(boolean) in the type PrintWriter is not applicable for the arguments (void)."  So the class PrintWriter has a method println() that takes a boolean as its parameter.  But the argument passed is a type void.  You have a mismatch between the parameter and argument types. The important part is the argument type.  It's void.  Why?  Because that's the way you defined it.
You could make the method return a String and this would normally be fine, but is that going to work in this situation?  No, because the method is recursive (it calls itself).  So we're going to have to logically put the posting code into the method. (But practically, create a method called postToFile() or something and call this from combinationUtil()).

So somewhere around to 21, create a String and pass it to the new printing method.  Post what you've done.

(The second error message just tells you to delete the token "int".  A token is just a logical chunk of code.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!