Va kommunikatsiyalarini rivojlantirish vazirligi muhammad al xorazmiy nomidagi toshkent axborot texnologiyalari universiteti


Download 0.72 Mb.
bet3/4
Sana19.11.2020
Hajmi0.72 Mb.
#147534
1   2   3   4
Bog'liq
Mahkamov Farhod TDA lab-3


Dastur kodi:
package createdb;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class CreateDB {

static final String DATABASE_URL = "jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull";

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";

static final String USER = "root";

static final String PASSWORD = "**************";

public static void main(String[] args) throws ClassNotFoundException, SQLException {

Connection connection = null;

Statement statement = null;

try {


System.out.println("JDBC drayverni ro‘yxatdan o‘tkazish...");

Class.forName(JDBC_DRIVER);

System.out.println("Ma'lumotlar bazasiga bog‘lanish...");

connection = DriverManager.getConnection(DATABASE_URL, USER, PASSWORD);

System.out.println("Ma'lumotlar bazasini yaratish...");

statement = connection.createStatement();

String SQL = "CREATE DATABASE MahkamovFarhod";

statement.executeUpdate(SQL);

System.out.println("Ma'lumotlar bazasi muvaffaqiyatli yaratildi...");

}

finally {



if(statement!=null){

statement.close();

}

if(connection!=null){



connection.close();

} } } }



  1. NetBeans IDE 8.2 ga MySQLning ma’lumotlar bazasida ishlash uchun Driverlarni sozlab olamiz.

“Добавить файл JAR/папку”



“mysql-connector-java-5.1.49.jar”



“Новое соединение…”



«Новый драйвер…»



“Добавить… tugmasini bosgan holda mysql-connector-java-5.1.4.jar driverini joylashuvini ko’rsatamiz”



“Далее > tugmasi bosiladi”



“Имя пользователя va Пароль ni terganimizdan keyin Далее > tugmasi bosiladi”



“So’ngi jarayonda Готово tugmasi bosiladi”



  1. Download 0.72 Mb.

    Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling