Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create database and table from jsp page
12-13-2011, 03:06 AM (This post was last modified: 12-13-2011 03:08 AM by rajasri.)
Post: #1
Sad Create database and table from jsp page
Today we are going to learn simple method to create the database and table from jsp code.
Just create a simple jsp page ex:create.jsp and paste the code below

<%@page import="java.sql.*,java.io.*" %>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/","root","root");
PreparedStatement ps=con.prepareStatement("create database s2sgateway");
ps.executeUpdate();
PreparedStatement ps1=con.prepareStatement("use s2sgateway");
ps1.executeUpdate();
PreparedStatement ps2=con.prepareStatement("create table new(name varchar(20))");
ps2.executeUpdate();

%>


database created sucessfully
Table create successfully

After executing you could see a database named s2sgateway and a table named new under s2sgateway has been created.
Here i use mysql if you use other database change the driver and connection settings accordingly any doubt ask us.

Happy coding
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Hsqldb another database how to use it. mjm 0 196 01-03-2012 04:32 AM
Last Post: mjm
Tongue Finding/removing duplicate values from database using sql rajasri 0 61 12-19-2011 10:17 PM
Last Post: rajasri
  Display data from database in php rajasri 0 187 12-14-2011 04:22 PM
Last Post: rajasri
Smile How to backup database of mysql using bat rajasri 0 176 12-13-2011 02:41 AM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)


WE will share important jobs and updates on facebook so like us to get updates