How to Create a Table in Java JDBC, Creating a Table into a Database by Java Database Connectivity
The Java provides the very large number of Classes to make the connectivity to the Databases, These classes comes under the java.sql package and the Java uses Open Database connectivity procedure to do this task and this technique called in java as Java Database Connectivity (JDBC). With the help of JDBC we can make a connection to the Database and fire the query for creating Objects (tables, view), inserting data into the Objects (tables, view), deleting Objects (tables, view), creating joins etc.
we are looking for creating a table into the Database by JDBC.
So, here is an example for creating a table into database.
Example:-
import java.sql.*
public class CreateTable
{
public static void main(String st[])
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement stm=con.createStatement();
int ch=stm.executeUpdate("create table students(roll_no number(10),stu_name varchar(30),stu_address varchar(100),stu_contact number(10),stu_course varchar(20))");
if(ch>0)
System.out.println("Table Created Successfully!");
else
System.out.println("There is a problam for creating a Table!");
}
}
The Java provides the very large number of Classes to make the connectivity to the Databases, These classes comes under the java.sql package and the Java uses Open Database connectivity procedure to do this task and this technique called in java as Java Database Connectivity (JDBC). With the help of JDBC we can make a connection to the Database and fire the query for creating Objects (tables, view), inserting data into the Objects (tables, view), deleting Objects (tables, view), creating joins etc.
we are looking for creating a table into the Database by JDBC.
So, here is an example for creating a table into database.
Example:-
import java.sql.*
public class CreateTable
{
public static void main(String st[])
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement stm=con.createStatement();
int ch=stm.executeUpdate("create table students(roll_no number(10),stu_name varchar(30),stu_address varchar(100),stu_contact number(10),stu_course varchar(20))");
if(ch>0)
System.out.println("Table Created Successfully!");
else
System.out.println("There is a problam for creating a Table!");
}
}
Thanks for visiting
{ 0 comments... read them below or add one }
Post a Comment