Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Able to create a connection from a new project to an Oracle db
Able to create a connection from a new project to an Oracle db [message #237233] Tue, 09 October 2007 22:52 Go to next message
Eclipse UserFriend
Originally posted by: subi_peg.yahoo.com

I have the following code in a connect.java file
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Connect {
public static void main(String[] arguments) {
String data = "jdbc:odbc:UUUU04";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(
data, "YYYYYYY", "XXXXXX");
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery(
"SELECT FNM, LNM, MIN, TITLE, MAX_EDU " +
"FROM pep " );
System.out.println("First Name /t Last name/t TITLE /t
User ID " +
"People in PEP file ");
while(rec.next()) {
System.out.println(rec.getString("FNM")+ "\t"
+ rec.getString("LNM")+ "\t"
+ rec.getString("MIN")+ "\t"
+ rec.getString("TITLE")+ "\t"
+ rec.getString("MAX_EDU") );
}
st.close();

} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception e) {
System.out.println("Error: " + e.toString()
+ e.getMessage());
}
}

}


What I am hoping to do is make this a common connect class
which could them be included in all source files.
Here is what I had in mind

after the changes I had in mind it would look like
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Connect {
public static void main(String[] arguments) {
String data = "jdbc:odbc:RASID04";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(
data, "VGI_DEV10S", "vgidev123m");
Statement st = conn.createStatement();


} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception e) {
System.out.println("Error: " + e.toString()
+ e.getMessage());
}
}

}

SO if I created a test first for an class Pep
the testPep junit test file should look like the below however I am not
able to get it work


package vgio4d10s;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import junit.framework.TestCase;
import vgio4d10s.Connect;


public class testPep extends TestCase {

public void testGetPep(){
/** this would look for the record with the max pep_id then the assert
equals would test
* the value with the value that has been converted to a string only
because it is too long for long
* integer. also a nother assertEquals would test the first name */
Connect();
ResultSet rec = rs.executeQuery("Select * from PEP where pep_id =
(select Max(pep_id)from pep)");
String mPid = rec.getNString("PEP_ID");
String mFnm = rec.getString("FNM");


assertEquals("10000000000000001026", mPid);

}



}

/**
*the Connect () <- throws error the method connect is undefined for type
testPep */


If you know of any small example that was created using the TDD
methodology then I could learn from it and not keep bothering you folks
Either way the fact that you are trying to help some one is appreciated
Re: Able to create a connection from a new project to an Oracle db [message #237245 is a reply to message #237233] Wed, 10 October 2007 00:20 Go to previous message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Subi wrote:
> I have the following code in a connect.java file import
> java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> public class Connect {
> public static void main(String[] arguments) {
> String data = "jdbc:odbc:UUUU04";
> try {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> Connection conn = DriverManager.getConnection(
> data, "YYYYYYY", "XXXXXX");
> Statement st = conn.createStatement();
> ResultSet rec = st.executeQuery(
> "SELECT FNM, LNM, MIN, TITLE, MAX_EDU " +
> "FROM pep " );
> System.out.println("First Name /t Last name/t TITLE /t
> User ID " +
> "People in PEP file ");
> while(rec.next()) {
> System.out.println(rec.getString("FNM")+ "\t"
> + rec.getString("LNM")+ "\t"
> + rec.getString("MIN")+ "\t"
> + rec.getString("TITLE")+ "\t"
> + rec.getString("MAX_EDU") );
> }
> st.close();
> } catch (SQLException s) {
> System.out.println("SQL Error: " + s.toString() + " "
> + s.getErrorCode() + " " + s.getSQLState());
> } catch (Exception e) {
> System.out.println("Error: " + e.toString()
> + e.getMessage());
> }
> }
>
> }
>
>
> What I am hoping to do is make this a common connect class which could
> them be included in all source files.
> Here is what I had in mind
> after the changes I had in mind it would look like import
> java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> public class Connect {
> public static void main(String[] arguments) {
> String data = "jdbc:odbc:RASID04";
> try {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> Connection conn = DriverManager.getConnection(
> data, "VGI_DEV10S", "vgidev123m");
> Statement st = conn.createStatement();
> } catch (SQLException s) {
> System.out.println("SQL Error: " + s.toString() + " "
> + s.getErrorCode() + " " + s.getSQLState());
> } catch (Exception e) {
> System.out.println("Error: " + e.toString()
> + e.getMessage());
> }
> }
>
> }
>
> SO if I created a test first for an class Pep
> the testPep junit test file should look like the below however I am not
> able to get it work
>
> package vgio4d10s;
>
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> import junit.framework.TestCase;
> import vgio4d10s.Connect;
>
>
> public class testPep extends TestCase {
>
> public void testGetPep(){
> /** this would look for the record with the max pep_id then the
> assert equals would test * the value with the value that has
> been converted to a string only because it is too long for long
> * integer. also a nother assertEquals would test the first name */
> Connect();
> ResultSet rec = rs.executeQuery("Select * from PEP where pep_id
> = (select Max(pep_id)from pep)");
> String mPid = rec.getNString("PEP_ID");
> String mFnm = rec.getString("FNM");
>
>
> assertEquals("10000000000000001026", mPid);
>
> }
>
>
>
> }
>
> /**
> *the Connect () <- throws error the method connect is undefined for type
> testPep */
>
>
> If you know of any small example that was created using the TDD
> methodology then I could learn from it and not keep bothering you folks
> Either way the fact that you are trying to help some one is appreciated
>
There are numerous problems with this code. It really looks like you
are struggling with basic Java concepts. You should probably spend some
time learning the Java language first. I would suggest you get some
introductory Java programming books to start with.

These types of questions really aren't appropriate for this news group.
The group is for questions regarding Eclipse and not Java.
Previous Topic:Error on Aptana Plug-in Install
Next Topic:[PDE] disabled activity to remove views
Goto Forum:
  


Current Time: Sat Apr 27 03:10:38 GMT 2024

Powered by FUDForum. Page generated in 0.09042 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top