This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Databse Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Databse Problem" Watch "Databse Problem" New topic
Author

Databse Problem

Nee Kat
Ranch Hand

Joined: Jan 27, 2004
Posts: 37
I ma trying to use this class for databse connection but the code is not compiling and I am getting missing return statement error.
I am not able to debug it. PLease help.

Here is the code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import oracle.jdbc.driver.*;


public class DatabaseConnection{

Connection connection = null;
String present = "";
public String getDBname()
{
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName("oracle.jdbc.driver.OracleDriver");

// Create a connection to the database
String serverName = "135.51.32.169";
String portNumber = "1521";
String sid = "admindb";
String url = "jdbc racle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "amst";
String password = "b1indne$$";
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();

ResultSet firstdb;
firstdb = stmt.executeQuery("SELECT present FROM auser.sid");
while ( firstdb.next() )
{
present = firstdb.getString("present");
System.out.println("The output we getting from auser.sid is "+present);
}
connection.close();
}
catch (ClassNotFoundException e)
{

}
catch (SQLException e)
{

}
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Your method "getDBname()" is declared as returning String, but there are no "return" statements in it anywhere. You could either change that "String" to "void", or have the method return something.

Since we're really talking about Java fundamentals, here, I'm going to move this to our Java beginner's forum.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Databse Problem
 
Similar Threads
Problem in returning the username
What does the line Class.forName("oracle.jdbc.OracleDriver"); actually do?
Java to Display Data from Database
problem in connecting to oracle through jdbc
connecting to oracle db problem