Total Answers and Comments: 9
Last Update: July 15, 2008 Asked by: jagadesh05
No best answer available. Please pick the good answer available or submit your answer.
February 13, 2008 23:32:35 #5
sampra
Member Since: February 2008 Contribution: 279
RE: JDBC Type1 drivers Java Test
/*create table student
(
sid number(5),
sname char(15),
email char(15),
phone number(12)
); */
import java.sql.*;
class Test
{
public static void main(String as[])
{
try{
int sid=Integer.parseInt(as[0]);
String sname=as[1];
String email=as[2];
long phone=Long.parseLong(as[3]);
//step 1-load the class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//step 2-establish the connection
Connection con=DriverManager.getConnection("jdbc:odbc:studentDSN","scott","tiger");
//step 3 create the statment
Statement st=con.createStatement();
//step 4 prepare sql queary and execute
String sql="insert into student values("+sid+",'"+sname+"','"+email+"',"+phone+")";
int x=st.executeUpdate(sql);
//step 5..process result
if(x==1)
{
System.out.println("Inserted...");
}
else
{
System.out.println("Not.Inserted");
}
//step 6-clean up
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
Is this answer useful? Yes | No
Go To Top