Wednesday, June 11, 2008

I am still working on JDBC- this is one of my classes which has a connect and close method

import java.util.*;
import java.sql.*;

public class DatabaseUtils
{
public static Connection con(String driver- String url- String username- String password)
throws ClassNotFoundException- SQLException
{
Class.forName(driver);

return DriverManager.getConnection(url- username- password);
}

// Similar methods to close Statement and ResultSet
public static void close(Connection connection)
{
try
{
if (connection != null)
{
connection.close();
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
Heres another class which uses the DatabaseUtils class

import java.util.*;
import java.sql.*;

public class PersonDAO{

public void savePerson(PersonInfo person)
{

String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String userName = "jason";
String passWord = "donavan";


try
{
Connection con = DatabaseUtils.con(driver- url- userName- passWord);

String sql = "INSERT INTO Person(name- idNo- " +
"userName- passWord) VALUES (?-?-?-?) ";

// Create a Preparedstatement
PreparedStatement ps = con.prepareStatement(sql);

ps.setString(1- person.getName());
ps.setString(2- person.getIdNo());
ps.setString(3- person.getUsername());
ps.setString(4- person.getPassword());

ps.executeUpdate();
}
catch(Exception e){
System.out.println(e);
}
}

}// end class PersonDAO
But what i need to do is make Connection a private data member in my PersonDao implementation instead of instantiates its own Connection. How would i do this?
cheers

I m wondering what will be the better choice between a MacBook Pro or a Dell XPS- both roughly $2-000. I m going to be mostly doing Computer programming ( html- java- scripting and so on )- Game design & Digital design- Computer Animation. I also like to play games smoothly without any problems also

I ve been reading about Macs quite a bit and doing alot of research- been using a pc for about 6 years and vista is bullshit that i d like to never use again. I m worried though that if I get a Mac I won t be able to do some of the things I would on an XP gaming wise.

Basically..what do macs have that PC s don t- other then vista?

Could anyone actually give me the code or the procedure to create a textbox on a java page be it an applet or bean- that is resizable and can be positioned anywhere in that particular window. If this is not possible- please suggest a way by which positioning of the textbox(dynamic)is possible by giving co-ordinates via keyboard without using the mouse.

My project involves creating a java page that is essentially not a web page and when some input is given- a provision has to be made to save the page as a template in xml(i was asked to do in pgf format). later in another java page- a list of all saved templates have to be displayed from which one can be selected. I was wondering if anyone could help me with the java to xml saving. Please help. I have only a week left. and also suggest whether these could be done using applets or can be done only using bean.:-)

No comments: