Tech Support Guy banner
Status
Not open for further replies.
1 - 5 of 5 Posts

· Registered
Joined
·
19 Posts
Discussion Starter · #1 ·
Hi I wonder if theres anyone who could help me here please? I have been assigned with a project to view tables made in SQL and Oracle in Java. I have been reading some what and found something on java.sql but I am not sure implement it. It has been difficult(for me) to find any decent informatino in books and the internet. The Sun website is very confusing:(

Any help on this topic would be great thank you.
 

· Registered
Joined
·
11 Posts
I have done it using JDBC-ODBC bridge. You need to install this driver and set up a dsn to the databases. If you want the java code to do the connection I can provide some basic stuff that worked for me. I would not consider myself a pro in any sense in java, but I got data out ofa Access and SQL database.
 

· Registered
Joined
·
11 Posts
Here is code to open database.

import java.sql.*;

public class openDatabase
{
public Connection conn;
public boolean dbOpen;

public openDatabase()
{
databaseStatus dbs;
dbs = new databaseStatus();
int result = dbs.getStatus();
try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn = DriverManager.getConnection("JDBC:ODBC:newmar","admin","");
}
catch(SQLException ex)
{
System.out.println("excp");
System.out.println ("\n*** SQLException caught ***\n");
while (ex != null)
{
System.out.println ("SQLState: " +
ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " +
ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
result++;
}
}
catch(Exception ex)
{
System.out.println(ex);
System.out.println("open Fail");
result++;
}
dbs.getDbStatus(result);
dbs.getStatus();
}
}
 

· Registered
Joined
·
11 Posts
public ResultSet returnCusRS()
{
return rsCus;
}
/**
*
* @param c
* @param b
* @return rsCus
*/
public ResultSet readCust(Connection c, String b)
{
conn = c;
customer cr = new customer();
cr.setKey(b);
/**
*
*/
try
{
java.sql.PreparedStatement stmt =
conn.prepareStatement(
"Select * from Customer where CustomerId = ?");
stmt.setString(1, b);

rsCus = stmt.executeQuery();
}
/**
*
*/
catch (Exception ex)
{
System.out.println(ex);
rsCus = null;
}
/**
*
*/
return rsCus;
}
/**
*
* @param c
* @return rsCus
*/
public ResultSet readCust(Connection c)
{
conn = c;
try
{
Statement stmt = conn.createStatement();

rsCus = stmt.executeQuery("select * from Customer");

}
catch (Exception ex)
{
System.out.println(ex);
rsCus = null;
}
return rsCus;
}
/**
*
* @param c
* @param a
* @param b
* @return rSCus
*/
public ResultSet readCust(Connection c, String a, String b)
{
conn = c;
try
{
java.sql.PreparedStatement stmt =
conn.prepareStatement(
"Select * from Customer where ActiveCustomer = Yes");

rsCus = stmt.executeQuery();
}
catch (Exception ex)
{
System.out.println(ex);
rsCus = null;
}
return rsCus;
}
/**
*
* @param co
* @param b
* @param c
*/
public void updatecust1(Connection co, String b, customer c)
{
conn = co;
customer cr = new customer();
cr.setKey(b);
cr = c;
System.out.println(cr);
System.out.println(cr.custId);
System.out.println(cr.workPhone);
System.out.println(cr.activeCustomer);
String updateString = " ";

try
{

Statement stmt = conn.createStatement();
try
{
if (cr.activeCustomer == true)
{
if (cr.citrixId.length() == 0)
{
updateString =
"UPDATE Customer "
+ "Set Company='"
+ cr.custNam
+ "', WorkPhone='"
+ cr.workPhone
+ "', Customer.Money = '"
+ cr.turnOver
+ "', Staff = '"
+ cr.staff
+ "', ITStaff = '"
+ cr.itStaff
+ "', ActiveCustomer = "
+ cr.activeCustomer
+ ", StatusID = '"
+ cr.statusId
+ "', Customer.[I-KonicID] = '"
+ cr.ikonicId
+ "', Customer.TypeOfBusiness = '"
+ cr.typeofBusiness
+ "', WebSite = '"
+ cr.webSite
+ "', MultiSite = "
+ cr.multiSite
+ ", CitrixID = '"
+ cr.citrixId
+ "' WHERE CustomerID="
+ cr.custId;
}
else
{
updateString =
"UPDATE Customer "
+ "Set Company='"
+ cr.custNam
+ "', WorkPhone='"
+ cr.workPhone
+ "', Customer.Money = '"
+ cr.turnOver
+ "', Staff = '"
+ cr.staff
+ "', ITStaff = '"
+ cr.itStaff
+ "', ActiveCustomer = "
+ cr.activeCustomer
+ ", StatusID = '"
+ cr.statusId
+ "', Customer.TypeOfBusiness = '"
+ cr.typeofBusiness
+ "', WebSite = '"
+ cr.webSite
+ "', MultiSite = "
+ cr.multiSite
+ ", CitrixID = '"
+ cr.citrixId
+ "', Customer.CitrixExpire = '"
+ cr.citrixExpire
+ "' WHERE CustomerID="
+ cr.custId;
}
}
else
{
updateString =
"UPDATE Customer "
+ "Set Company='"
+ cr.custNam
+ "', WorkPhone='"
+ cr.workPhone
+ "', Customer.Money = '"
+ cr.turnOver
+ "', Staff = '"
+ cr.staff
+ "', ITStaff = '"
+ cr.itStaff
+ "', ActiveCustomer = "
+ cr.activeCustomer
+ ", StatusID = '"
+ cr.statusId
+ "', Customer.TypeOfBusiness = '"
+ cr.typeofBusiness
+ "', WebSite = '"
+ cr.webSite
+ "', MultiSite = "
+ cr.multiSite
+ " WHERE CustomerID="
+ cr.custId;
}

System.out.println(updateString);
stmt.execute(updateString);
}
catch (Exception ex)
{
System.out.println(ex);
}
}
catch (Exception ex)
{
System.out.println(ex);
}
}
 
1 - 5 of 5 Posts
Status
Not open for further replies.
Top