What is the process to make connectivity with database in Java?
Give me the full syntax of database connectivity?
Printable View
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);
[URL="http://www.acm.org/crossroads/columns/ovp/march2001.html"]MORE INFORMATION....[/URL]
--------------------------
suresh
[quote=santhisudha;18712]What is the process to make connectivity with database in Java?
Give me the full syntax of database connectivity?[/quote]
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("jdbc:oracle:thin:@localhost:1521:orcl","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 [URL]http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=5551&lngWId=2[/URL]