Results 1 to 4 of 4
- 10-14-2009, 09:22 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 16
- Rep Power
- 0
can't return a value from a method / jdbc
Hello I ahve a problem with returning a String value from "JdbcBean" to Main Class.
JdbcBean:
public class JdbcBean {
Connection conn;
public String getColumn(int sloupecek) {
String sloupec1 = new String();
try {
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@xxx ", "xxx", "xxx");
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("select * from student");
while (r.next()) {
sloupec1 = r.getString(sloupecek);
return sloupec1;
}
r.close();
s.close();
conn.close();
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
}
}
MainClass:
public class MainPokus {
public static void main(String[] args) {
JdbcBean spojeni = new JdbcBean();
System.out.println(spojeni.getColumn(2));
}
}
Exception:
Error(23,24): can't return a value from method whose result type is void
Have anyone any advice for me?
I am a begginer in Jdbc database get data. :(
Thanks a lot.Last edited by tascoa; 10-14-2009 at 09:40 PM.
- 10-14-2009, 09:31 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You need to learn the Java basics before trying to connect to databases.
Your method is void but you have return statements inside it.
- 10-14-2009, 09:34 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 16
- Rep Power
- 0
I am sorry, the void is wrong, It my mistake. But if I erase void word, the error is the same...
- 10-15-2009, 01:02 PM #4
Similar Threads
-
Return an object to use in another method
By TidusSolan in forum New To JavaReplies: 3Last Post: 03-19-2009, 08:00 PM -
method that return 2 arguments
By itaipee in forum New To JavaReplies: 19Last Post: 01-12-2009, 05:36 PM -
return a null method
By valoyivd in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:19 PM -
Return question in a method.
By MetalGear in forum New To JavaReplies: 1Last Post: 01-13-2008, 04:45 AM -
Return value of method
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 08:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks