What is the process to make connectivity with database in Java?
Give me the full syntax of database connectivity?
What is the process to make connectivity with database in Java?
Give me the full syntax of database connectivity?
Properties props = new Properties();
props.setProperty("user", "contacts");
props.setProperty("password", "blackbook");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/contacts/", props);
Statement stmt = con.createStatement();
String query = ... // define query
stmt.executeQuery(query);
MORE INFORMATION....
--------------------------
suresh
import java.sql.*;
class Test
{
public static void main(String args[]) throws SQLException
{
String s;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection cn=DriverManager.getConnection("jdbcracle:thin:@localhost:1521rcl","scott","t");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select * from dept");
while(rs.next())
{
System.out.println(rs.getString(1));
}
st.close();
cn.close();
}
catch(Exception ex)
{
System.out.println("The exception raised is : " + ex);
}
}
}
you need to set classpath and path
for that refer http://www.planet-source-code.com/vb...=5551&lngWId=2
Last edited by admin; 10-03-2007 at 06:42 PM.