Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-05 08:40:57
I had originally thought of building a tree (char by char) or using something like a hashmap or hashset, but I was concerned because I didn't want to have to build the tree or hashset at the beginning of each running of the game. For instance when I was building my tree, it took almost 3 minutes to populate the tree with every path of valid words, plus I realized with building a tree that you would have to make a tree for each length of word assuming that you check for a valid word by seeing if the next node is null. However I suppose you could make a tree with nodes of two elements one is the char and two is a boolean saying if ending on this node maps the path of a valid word. Unless I am confused, I don't think I want to use a tree structure. Also, I am still concerned about the hashset... does it take too much build/initialization time?
2  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-05 06:17:57
If I do something like a hashmap or .txt files is the best way of checking to do a String.compareTo()... or is there a different/better way?
3  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-04 18:04:14
Okay, that makes sense.

So it would really be faster to read through a file every time I want to check for a word rather than connect to a database at the beginning of the game and have O(1) search time the rest of the game?

Also, I had planned to use the database for a few extra things, for instance, there were some extra columns with the word list the contained how many points each word was worth as well as some other statistics about each word, this was all calculated at the time of populating the database, that way I wouldn't have to do it each time the user entered a word in actual game play.
4  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-04 06:15:16
Ooh, I considered that idea a while ago, but didn't go anywhere with it. Would that work in the context of a web applet?
5  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-04 05:56:24
I was looking at SQLLite, do I do the same coding as I have been doing and this is just a different driver in order to access my database?

Also, I have never done a project like this before and I am wondering once I have my word game complete (probably just with GUI) and a word list that I am happy with (stored in a database), how do I make this accessible to anyone? I am thinking of making it into an applet that will be on my website, do i need to have my database stored somewhere so that anyone from any computer can play the game and the game will be able to access the database?
6  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-04 03:44:56
Well, the list has a little over 200,000 words, I am trying to get a slightly more extensive one though. Anyway, I considered a hashmap, but I don't really know anything about Hashsets. What do you suggest instead of a database, it seems to be working okay so far?
7  Java Game APIs & Engines / Tools Discussion / Re: Problems with JDBC on: 2009-01-02 02:09:36
I was wondering if mySQL might be a better way to go as far as databases go. Mostly, I went with Access because it was already on my machine. Where do I find a driver for that? Also, when you say I need to include it in my project library, do you mean the that the sql driver is a jar file and I need to add it to the compile time libraries?
8  Java Game APIs & Engines / Tools Discussion / Problems with JDBC on: 2009-01-01 00:43:50
I am trying to make a word game and obviously I need a word list to check the correctness of the words that people enter, so I found a .txt file containing all the words I could ever want and wrote some code to have the .txt file loaded line by line into a database using Java Database Connectivity, but now I am trying to query the database to see if it can retrieve information from the database. If it isn't able to retrieve anything, then it will tell the user that it is not a word, but if it is able to retrieve info, that means the word is in the database and therefore is a real word... My program doesn't work though, it keeps giving me the following error when I run it at the point in time that it tries to query the database...

ERROR: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Here is the code I am using, any ideas?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
/*
 * The purpose of this class is to test that I can connect to the database
 * I created with WordDBMaker.java and WordDBLoader.java and query the database
 * to check that words the user enters are in the database and therefore valid
 * words.
 */


/**
 * @author Josh Branchaud
 * @version 12/30/2008
 */


//*************************************
//***** Imported Classes **************
//*************************************
// added for reading user input from the console
import java.util.Scanner;

// added for connecting to and querying the database
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.ResultSet;

public class WordDBTester
{
    // create a volatile boolean variable for knowing when to end execution
   public volatile boolean endExecution = false;

    // the main method for this class
   public static void main(String[] args)
    {
        WordDBTester WDBT = new WordDBTester();

        // Scanner called in for reading user input from the console
       Scanner in = new Scanner(System.in);

        // try/catch block for connecting to the database and querying it.
       try
        {
            // specifying the driver we want to use for database connection
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            // String variable holding the location of the database
           String DBLocation = "jdbc:odbc:WordList1";

            // connect to the database found at DBLocation
           Connection DBConnection = DriverManager.getConnection(DBLocation);

            // system message for confirmation of connection to the database
           System.out.println("Successfully connected to " + DBLocation);

            Statement s1 = DBConnection.createStatement();

            while(!(WDBT.endExecution))
            {
                System.out.println("Type 'quit!' if you would like to exit, otherwise");
                System.out.print("enter the word you would like to check: ");

                String inputWord = "";

                inputWord = in.nextLine();

                System.out.println("");

                if(inputWord.compareTo("quit!") == 0)
                {
                    WDBT.endExecution = true;
                    break;
                }

                System.out.println("The word you are checking for is " + inputWord);

                String wordQuery = "SELECT * FROM WordList1 WHERE Word = " + inputWord;

                System.out.println("The query looks like " + wordQuery);

                ResultSet rs = s1.executeQuery(wordQuery);

                int resultCount = 0;
                String thisWord = "";
                int pointValue = 0;

                while(rs.next())
                {
                    resultCount++;

                    thisWord = rs.getString("Word");
                    pointValue = rs.getInt("Points");
                }

                if(resultCount == 0)
                {
                    System.out.println("Sorry, but " + inputWord + " is not a word.");
                }
                else
                {
                    System.out.println(thisWord + " is a word and it is worth " + pointValue + " points.");
                }
            }

            // disconnect from the database
           DBConnection.close();

            // confirmation message of the disconnection from the database
           System.out.println("Disconnection successful!");
        }
        catch(ClassNotFoundException CNFError)
        {
            System.out.println("ERROR: " + CNFError);
        }
        catch(SQLException SQLError)
        {
            System.out.println("ERROR: " + SQLError);
        }
        catch(Exception Error)
        {
            System.out.println("ERROR: " + Error);
        }
    }
}


Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!