• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Databse Problem

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
{

}
}
}
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic