Executing SQL Query
Output:
The output is based on your program database connectivity.
And finally we are in the last step of the Jdbc connectivity. Here we're execute the SQL Queries.
package com.sathish.jdbc.project;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.lang.ClassNotFoundException;
public class Create_Table {
public
static void main(String[] args)
{
Connection
connection=null;
Statement
statement=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
connection
=DriverManager.getConnection("jdbc:mysql://localhost:3306/my_testing","root","");
statement
= connection.createStatement();
statement.execute("create
table sathishkumar(id INT(10) NOT NULL,sathish varchar(100))");
System.out.println("SQL
Query Executed Successfully");
}
catch(ClassNotFoundException
error)
{
System.out.println("Error:"+error.getMessage());
}
catch(SQLException
error)
{
System.out.println("Error:"
+error.getMessage());
}
finally
{
if(connection !=null)
try {
connection.close();
}catch(SQLException ignore){}
if(statement !=null)
try {
statement.close();
}catch(SQLException ignore){}
}
}
}
Output:
The output is based on your program database connectivity.
No comments:
Post a Comment