Results 1 to 3 of 3
- 03-17-2013, 08:51 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 11
- Rep Power
- 0
Help with this class implementing JDBC
Hi there I have this class:
I would really like to get explained what is happening in these lines:Java Code:import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class ConnTest { public static void main(String args[]){ String dbuser = "db_abc"; String passwd = "yourpassword"; Connection conn; int port = 1521; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:"+port+":dbwc", dbuser, passwd); conn.setAutoCommit(false); PreparedStatement s = conn.prepareStatement("Select * from Ships"); ResultSet rs = s.executeQuery(); while (rs.next()){ String sname = rs.getString(1); String sclass = rs.getString(2); String slaunched = rs.getString(3); System.out.println(sname + ":" + sclass + ":" + slaunched); } } catch(SQLException e) { System.out.println(e); } catch(ClassNotFoundException e) { System.out.println(e); } } }
What does this Class.forName do? And where is the DriverManager object created?Java Code:Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:"+port+":dbwc", dbuser, passwd);
- 03-18-2013, 02:58 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Help with this class implementing JDBC
You can read more on the following link: DriverManager (Java Platform SE 7 )Applications no longer need to explictly load JDBC drivers using Class.forName(). Existing programs which currently load JDBC drivers using Class.forName() will continue to work without modification.
When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.Website: Learn Java by Examples
- 03-18-2013, 10:00 AM #3
Similar Threads
-
implementing class and object
By mheyai09 in forum New To JavaReplies: 2Last Post: 07-19-2012, 01:18 PM -
Implementing Class Files Into Driver
By mike_ in forum New To JavaReplies: 5Last Post: 12-07-2011, 12:00 AM -
Need Urgent Help in Implementing Interface Class
By yel_hiei in forum New To JavaReplies: 4Last Post: 07-29-2010, 01:42 PM -
need help with implementing class
By ALH813 in forum New To JavaReplies: 3Last Post: 10-01-2009, 11:04 PM -
Help implementing JDBC
By mooey1232003 in forum New To JavaReplies: 6Last Post: 07-11-2007, 10:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks