Thursday, July 31, 2008

Java Database codes-for beginners

Steps for connecting and accessing Databases using Java-For Beginners

1> Establishing Connection

1> Load drivers
class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

2> Make Connection
Connection con=DriverManager.getConnection("dataSourceName","userName","password");

3> Creating JDBC statement
Statement stmt=con.createStatement();

4> For creation, Updation, Insertion, Deletion
stmt.executeUpdate(string query);

5> For Retieving values from the database
ResultSet rs=stmt.executeQuery(String query);
while(rs.next())
{
String str=rs.getString(fieldName);
Float fl=rs.getFloat(fieldName);
}
6> Closing the Connection
stmt.close();
con.close();



Note:-
1> before this database needs to be created.
2> data source name also needs to be created
http://support.microsoft.com/kb/305599
(for creating data source name.)

9 Comments:

Lady J said...

i was here also :)

MeOwChiE18 said...

here :D

MeOwChiE18 said...

:D woootttttttttt

MeOwChiE18 said...

weeeeeeeeeeeeeee


meow meow here~

Anonymous said...

I did my job!

money maker said...

great

Anonymous said...

I did my job!1

Home said...

Hi was here, want to make real money:
http://qyao.com/general.php?REF=66192

Home said...

read...