Previn

Create_db

Sep 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1.  
  2. package test_database;
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8.  
  9. public class Create_db {
  10.    
  11.     public static void main(String []arg)
  12.     {
  13.        
  14.                
  15.         Connection con;
  16.         PreparedStatement ps;
  17.         ResultSet rs;        
  18.        
  19.         try
  20.         {
  21.             Class.forName("com.mysql.jdbc.Driver");
  22.             con=DriverManager.getConnection("jdbc:mysql://localhost/","root","");
  23.             System.out.println("Server Connected");      
  24.            
  25.             //Create Database
  26.             ps=con.prepareStatement("create database Test");
  27.             ps.executeUpdate();
  28.             System.out.println("Database created");
  29.         }
  30.         catch(Exception e)
  31.         {
  32.             System.out.println(e);
  33.         }
  34.  
  35.     }
  36.    
  37. }
Add Comment
Please, Sign In to add comment