Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

chris le

Greenhorn
+ Follow
since Jul 30, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by chris le

Hey, thanks a lot guys. I'll take a look at those suggestions.

Take care,

Chris
Thanks for the help!
But here's another question along the same lines.
Why does it have to be in a loop to work.

I have tried this:

It doesn't match it because the cursor is still on the last record "John".
Why is this happening even after I user the first() method? I even tried the absolute method.

Any ideas?
Thanks!
Thanks for the help!
But here's another question along the same lines.
Why does it have to be in a loop to work.

I have tried this:

It doesn't match it because the cursor is still on the last record "John".
Why is this happening even after I user the first() method? I even tried the absolute method.

Any ideas?
Thanks!
15 years ago
Hey guys, I'm a ColdFusion developer and have just started into java.
In ColdFusion if you want to see if a string matched the name of a column value (from a database) you would do this:



How would I check for a value like this in Java?
Here's what I got:



Any ideas?
Thanks guys and take care,

Chris
Hey guys, I'm a ColdFusion developer and have just started into java.
In ColdFusion if you want to see if a string matched the name of a column value (from a database) you would do this:



How would I check for a value like this in Java?
Here's what I got:



Any ideas?
Thanks guys and take care,

Chris
15 years ago
It worked!! Thanks Jules!

Take care,

Chris
15 years ago
Hey Jules,

They're both in the same directory. And It compiles fine (the RetrieveData class that is) and even instantiates fine inside the Family2 class, I can call it's setDB method and pass in the appropriate arguments, so I don't think it would be a classpath issue. How else would I call the myResultSet variable that belongs to the RetrieveData class inside the Family class.
This is the only way I know of:

RetrieveData rd = new RetrieveData();

while (rd.myResultSet.next()){
...
}

Any ideas?

Thanks and take care,

Chris
15 years ago
Hey guys,
I wrote a class called 'RetrieveData' with a function that takes as it's arguments the jdbc driver, datasource, and sql code. It compiles fine without error.
However, once I bring it into another class, the other class doesn't recognize the variables from the 'RetrieveData' class. I'm pretty new to Java, so any help would be much appreciated.

take care,

Chris

Here's the code and error messages:


[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ August 20, 2004: Message edited by: Dirk Schreckmann ]
15 years ago
That helped out alot. I appreciate all your help.
Take care,

Chris
Thanks for responding!

Two questions:

1. Could you post a code sample? (still very new, and would like to compare with what I have)

2. It sounds like doing it that way will not allow me to set the variables to the result values and then print out values of the variables. Is this true?

Thank you all for your help!

Take care,

Chris
I'm sorry, I posted the wrong error message.
It should read:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3812)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java:5642)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:585)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:603)
at dataTest.People2.main(People2.java:58)
Exception in thread "main"


--sorry about that
Hey guys,

I'm fairly new to java and jdbc, and I keep getting this SQL Error.
I can't seem to figure it out. Any help would be much appreciated.

Take care,

Chris



/*
* People2.java
*
* Created on August 18, 2004, 9:07 AM
*/

package dataTest;

import java.sql.*;


public class People2 {


//SET VARIABLES
private int id;
private String firstname;
private String lastname;
private String myStatement;


public static void main(String[] args)throws SQLException{

People2 p = new People2();

//SET CONNECTION OBJECTS
java.sql.Connection dbConn = null;
Statement myStatement = null;


//============ START DATABASE CONNECTION =============

try{

//LOAD THE DRIVER CLASS
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}catch(Exception e){
System.out.println(e.getMessage());
}//end catch

//SET ODBC DATASOURCE
String dsSource = "jdbc dbc sJava";

//GET A CONNECTION TO THE DATABASE
dbConn = DriverManager.getConnection(dsSource);

//CREATE A STATEMENT OBJECT
myStatement = dbConn.createStatement();

//CREATE VARIBLE TO HOLD SQL COMMAND
String sqlString = "SELECT * FROM people";

//CREATE A RESULTSET
ResultSet myResultSet = myStatement.executeQuery(sqlString);

//SET VARIABLES TO RESULTSET VALUES
p.id = myResultSet.getInt("id");
p.firstname = myResultSet.getString("firstname");
p.lastname = myResultSet.getString("lastname");

while(myResultSet.next()){
System.out.println("ID: " + p.id);
System.out.println("FirstName: " + p.firstname);
System.out.println("LastName: " + p.lastname);
}//end while loop

//CLOSE ALL OBJECTS
myStatement.close();
dbConn.close();
myResultSet.close();


}//end main()

}//end class


--------- THIS IS THE ERROR I'M GETTING -------------

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'people'. Make sure it exists and that its name is spelled correctly.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
at dataTest.People2.main(People2.java:55)
Exception in thread "main"
Hey thanks for all your help, I really appreciate it.

Take care,

Chris
16 years ago
Hey thanks for the response. I changed a few things, it compiles and runs but doesn't work right


1) fighter class

package example;

public abstract class fighter {

public int healthBar;

public abstract void taunt();
public abstract void deathmove();
public abstract int getHealth();

}//end fighter


2) life class

package example;

public class life {

public int takeLife(fighter f){
f.healthBar = f.healthBar - 1;
return f.healthBar;
}//end takelife()

}//end life

3) ninja class

package example;

public class ninja extends fighter {

public int healthBar = 20;

life l = new life();

public void taunt(){
System.out.println("Feel my cold steel!");
}//end taunt()

public void deathmove(){
System.out.println("Ninja has chopped off your head");
}//end deathmove()

public int getHealth(){
return this.healthBar;
}//end getHealth

public void punch(fighter f){
System.out.println("Pow!!Ninja has just punched you");
l.takeLife(f);
}//end punch()

}//end ninja

4) sumo class

package example;

public class sumo extends fighter {

public int healthBar = 20;

public void taunt(){
System.out.println("I will crush you!");
}//end taunt()

public int getHealth(){
return this.healthBar;
}//end getHealth()

public void deathmove(){
System.out.println("Sumo has snapped your neck");
}//end deathmove()

}//end sumo

5) areana class

package example;

public class areana{

public static void main(String[] args){

ninja n = new ninja();
sumo s = new sumo();

System.out.println("Sumo's life " + s.getHealth());

n.punch(s);

System.out.println("Sumo's life " + s.getHealth());

}//end main()


}//end areana


It compiles with no error, however the output is this:

--------------------
Sumo's life is 20
Pow!! Ninja has just punched you
Sumo's life is 20

----------------------

It doesn't subtract 1 from sumo's healthbar

Any ideas



Thanks,

Chris
16 years ago
Hey guys I'm writing a little fighter program and have gotten stuck. Here's the setup:

1) abstract fighter class

package example;

public abstract class fighter {

public int healthBar;

public abstract void taunt();
public abstract void deathmove();
public abstract int getHealth();

}//end fighter


2) abstract life class

package example;

public abstract class life {

public int takeLife(fighter f){
f.healthBar -= 1;
return f.healthBar;
}//end takelife()

}//end life

3) ninja class

package example;

public class ninja extends fighter {

public int healthBar = 20;

public void taunt(){
System.out.println("Feel my cold steel!");
}//end taunt()

public void deathmove(){
System.out.println("Ninja has chopped off your head");
}//end deathmove()

public int getHealth(){
return this.healthBar;
}//end getHealth

public void punch(life l){
System.out.println("Pow!!Ninja has just punched you");
l.takeLife(sumo);
}//end punch()

}//end ninja

4) sumo class

package example;

public class sumo {

public int healthBar = 20;

public void taunt(){
System.out.println("I will crush you!");
}//end taunt()

public int getHealth(){
return this.healthBar;
}//end getHealth()

public void deathmove(){
System.out.println("Sumo has snapped your neck");
}//end deathmove()

}//end sumo

Whenever I try to compile the ninja class I get this error:

example/ninja.java cannot resolve symbol
symbol: variable sumo
location: class example.ninja
l.takeLife(sumo);

1 error

It doesn't seem to like me passing the sumo object into that method. Any ideas would be greatly appreciated.

Thanks,

Chris
16 years ago