Java Connect to Microsoft SQL Server Step by Step

Ғылым және технология

Learn to write Java code that connects to Microsoft SQL Server. Understand how a Java program can connect to Microsoft SQL Server via JDBC (Java Database Connectivity).
Here's what you will learn in details:
- Create a table in Microsoft SQL Server Express using Microsoft SQL Server Management Studio (SSMS).
- Code the first Java project that connects to Microsoft SQL Server, and then insert a new row to a table. Download Microsoft JDBC driver for SQL Server.
- Understand database URL format for Microsoft SQL server.
- Code the second Java project using Microsoft JDBC driver with Maven. The program connects and get all rows from a table in Microsoft SQL Server database.
For text-based tutorial, read this: www.codejava.net/java-se/jdbc...

Пікірлер: 157

  • @RedDogByrd
    @RedDogByrd4 жыл бұрын

    I'm 77 and retired at 57. Haven't done any coding in over 20 years. Got bored in this pandemic. Never programmed in Java. Liked the idea of write once run anywhere. I did this video and got everything working in eclipse, but could not connect the db with Intellij which I prefer, but both are outstanding. Just started back coding in April. Nam you are fantastic. Keep up the good work. Why couldn't I be 10 years old again and have all this great technology at my finger tips?

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    Great to hear that from you, SIR. You motivated younger like me (I'm 37).

  • @achilleskocaeli
    @achilleskocaeli3 жыл бұрын

    Thanks mate. I can now connect to SQL server from Java. I am now immortal

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Haha, glad it could help.

  • @BRBearUSA
    @BRBearUSA3 жыл бұрын

    I confess I watched it at 2X the speed, but some nice step by step demonstrations without skipping steps. Definitely a good video for someone with 0 knowledge of Java SQL, wanting to see how it's accomplished. Thank you for the video.

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Glad it was helpful! Thanks for watching :)

  • @kpubemka
    @kpubemka4 жыл бұрын

    Nothing to add. Just a big THANK YOU!

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    Glad you liked it!

  • @gamtran3803
    @gamtran38034 жыл бұрын

    Thank you so much! It's very useful.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    Glad to hear that!

  • @manishmulchandani1541
    @manishmulchandani15413 жыл бұрын

    After so many videos found this a useful video, thumbs up (y)

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Glad it was helpful! Thanks for watching :)

  • @guadalupecastillo7281
    @guadalupecastillo72814 жыл бұрын

    Thanks! Just what I needed.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    You're welcome!

  • @iamaadityatiwari
    @iamaadityatiwari2 жыл бұрын

    Thanks man, It's been a long since I'm looking for this kind of Video, I was kinda getting bored because I was not getting something in the data base to play.

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    glad to hear that. Thanks for watching :)

  • @ticanabecks
    @ticanabecks Жыл бұрын

    Thank you for the video! Helped me a lot!

  • @CodeJava

    @CodeJava

    Жыл бұрын

    Glad it helped!

  • @playyourway2963
    @playyourway29633 жыл бұрын

    thank you so much, Very good explanation, and clear ...

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    You are welcome!

  • @ltilluck
    @ltilluck3 жыл бұрын

    This video helped me alot. Thanks!

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Glad it helped!

  • @vishalpatil8653
    @vishalpatil86534 жыл бұрын

    thanks alot sir ,it's very valuable for me :)

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    You are most welcome. Kindly subscribe!

  • @michaelthomheadley
    @michaelthomheadley3 жыл бұрын

    This really helped me out! Thanks

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Glad it helped!

  • @tranquan289
    @tranquan289 Жыл бұрын

    You made my day. Thank you so much!

  • @CodeJava

    @CodeJava

    Жыл бұрын

    Glad I could help!

  • @alinovskii
    @alinovskiiАй бұрын

    thank you so much, you really saved me!!

  • @CodeJava

    @CodeJava

    Ай бұрын

    You're welcome!

  • @N33T24
    @N33T242 жыл бұрын

    thankyou so much , that 's very helpful .

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    Glad it helped.

  • @rishabtyagi6571
    @rishabtyagi65714 жыл бұрын

    Seriously, It's very useful vedio ...Thanks a lot...Little bit problem of accent😅 to understand ...I am from India. But, apart from this it helped me a lot.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    You're welcome. Glad you found it helpful.

  • @rishabtyagi6571

    @rishabtyagi6571

    4 жыл бұрын

    @@CodeJava You are from where...??

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    I'm from Vietnam.

  • @shaloomciri1065
    @shaloomciri10654 жыл бұрын

    Merci beaucoup monsieur . genial

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    de rien. Also check this video: kzread.info/dash/bejne/Y6R1mJZmltLPqps.html

  • @vuongqtvn
    @vuongqtvn4 жыл бұрын

    nhìn giong bạn là biết người việt rồi cảm ơn bạn nhiều

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    Thanks. Subscribe?

  • @vuongqtvn

    @vuongqtvn

    4 жыл бұрын

    @@CodeJava yes subscribe

  • @zacknazar2804
    @zacknazar28043 жыл бұрын

    Much respect! Thank you!!!!

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    welcome, bro. Thanks for watching.

  • @KatRollo
    @KatRollo3 жыл бұрын

    Connection String: jdbc:sqlserver://:;instanceName=;databaseName= How to get server name and instance name in SSMS: Object Explorer > Your Connected Server (right-click) > Properties > General > Name

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    thanks for the tip. you rock!

  • @KatRollo

    @KatRollo

    3 жыл бұрын

    @@CodeJava You too, thanks for the video. It was my starting point.

  • @BabyWalrus
    @BabyWalrus3 ай бұрын

    thank you so much senor

  • @CodeJava

    @CodeJava

    2 ай бұрын

    You are most welcome. Glad it helped.

  • @daniafatima6199
    @daniafatima61993 жыл бұрын

    THANKYOU SO MUCH :)

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    You're welcome. Glad it helped :)

  • @user-hm9he9ve4h
    @user-hm9he9ve4h4 жыл бұрын

    I have many problem with that but u help me) But if u told about the SQL server auntification I'll make it faster (I m begginer)

  • @gizemkarauzum2440
    @gizemkarauzum24403 жыл бұрын

    thank you so much :))

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    You're welcome!

  • @Raphael2034
    @Raphael20342 жыл бұрын

    As I'm totally starting with Java, dumb question, is the JDK the same as Eclipse or do I need to download the latter separately? Thanks

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    In short, JDK is a software program needed to run Java apps, and Eclipse is a Java app. Read more details here: www.codejava.net/java-core/what-are-jvm-jre-and-jdk

  • @Raphael2034

    @Raphael2034

    2 жыл бұрын

    @@CodeJava wow that was quick. Also. are the codes listed here, will it work say I would embed them unto a HTML? Thanks

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    @@Raphael2034 I think you will find this tutorial helpful: www.codejava.net/java-ee/jsp/how-to-list-records-in-a-database-table-using-jsp-and-jstl

  • @Raphael2034

    @Raphael2034

    2 жыл бұрын

    @@CodeJava Awsome, this is actually what I need, except for slight deviation instead of MYSQL I'll be using MS SQL. Do you have an instruction weblink for such as well? Many thanks in advance

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    @@Raphael2034 yes, I do have one for MySQL here: kzread.info/dash/bejne/lql5zcpxitasd9Y.html

  • @paulocordeiro8565
    @paulocordeiro85653 жыл бұрын

    Thank you :)

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    You're welcome!

  • @yonnon6287
    @yonnon62873 жыл бұрын

    Em cám ơn anh nhiều !

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    welcome :)

  • @sihamjallabi3959
    @sihamjallabi39593 жыл бұрын

    Hi could you tell me how you manage the bug with special charset like a small a dieresis... JDBC did not like it hhh when you try to execute the dblink

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    why dblink here? I think it is for Oracle database, not SQL server, right?

  • @TechandArt
    @TechandArt3 жыл бұрын

    Grt learning

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Glad to hear that

  • @bogdanghinea7431
    @bogdanghinea7431 Жыл бұрын

    Thanks!

  • @CodeJava

    @CodeJava

    Жыл бұрын

    Welcome!

  • @saivenkatkavali8264
    @saivenkatkavali82643 жыл бұрын

    i have defined the dependency in pom and still not able to connect to sql database.im defining dependency in app-context.xml the bean isnot getting created. could not find dirver class exception

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    that means no JDBC driver for SQL server present in the classpath. Check the dependency and jar files

  • @nvs4600
    @nvs46003 жыл бұрын

    When I connect succeed and send full of file for other computers. How to they also run that program? (Connected sql)

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    I don't understand your question. Could you explain?

  • @h.mantri
    @h.mantri2 жыл бұрын

    Hey, can you please help me in connecting to database with ActiveDirectoryPassword authentication mechanism ?

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    Sorry, I don't know how to work with Active Directory.

  • @quangtranxuan6042
    @quangtranxuan60424 жыл бұрын

    cảm ơn bạn nhiều lắm , coi tới phần insert mới biết ng Việt Nam :))

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    You're welcome. Glad it helped. Subscribe?

  • @okolona1
    @okolona14 жыл бұрын

    Excellent and useful video. Too many close-ups. It is hard to read the code.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    thanks for your feedback.

  • @mmkgz
    @mmkgz3 жыл бұрын

    Nice video :D

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Thanks! 😁

  • @thangz0807
    @thangz0807 Жыл бұрын

    can you show the same implementations using visual studio code?

  • @CodeJava

    @CodeJava

    Жыл бұрын

    the code will be the same, regardless of IDE.

  • @josemardarioromanortega6428
    @josemardarioromanortega64282 жыл бұрын

    and how to make post to sql server? I cant find anything about that just, all the guys put their codes but never try to make post to the same data base

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    Isn't it described at 21:50? Execute SQL Insert statement?

  • @jenujohn584
    @jenujohn5843 жыл бұрын

    Com.microsoft. sqlserverdriver exception tcp/ip port error

  • @PankajKumar-su5dq
    @PankajKumar-su5dq4 жыл бұрын

    How to Connect to Remote SQL Server which requires Window authentications to connect, please keep me posted.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    You can't connect to remove SQL server using Windows authentication. You must use SQL server authentication.

  • @samedaydn872
    @samedaydn8724 жыл бұрын

    Hi Code Java, I got an error and I could not. I want to send you two screenshots. How can I reach you. This is my homework so it is very important. Please help.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    Sorry, I don't have time to support.

  • @theboringtechguy
    @theboringtechguy4 жыл бұрын

    I am getting conenction timeout error. Anyone knows what could be the issue?

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    do you connect to localhost or to different computer? If connect to SQL server on different computer, check firewall and enable TCP/IP in SQL server. You should post the full exception stack trace here so I can have more information to help.

  • @theboringtechguy

    @theboringtechguy

    4 жыл бұрын

    @@CodeJava I have created an instance in localhost.

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    so the database URL may be wrong. Check hostname, port number and database name.

  • @swathisivakumar6394
    @swathisivakumar6394 Жыл бұрын

    No suitable driver found for jdbc, pls help me

  • @CodeJava

    @CodeJava

    Жыл бұрын

    you need to add JDBC driver for SQL server. Follow this guide: www.codejava.net/java-se/jdbc/connect-to-microsoft-sql-server-via-jdbc

  • @aryavratmishra651
    @aryavratmishra6513 жыл бұрын

    For the connection URL, my server name is LAPTOP-5697KK36, but I don't have an instance name. How do I connect?

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Open Services manager and you will see the instance name of SQL server.

  • @aryavratmishra651

    @aryavratmishra651

    3 жыл бұрын

    @@CodeJava ​ I tried to do this, but there was no instance name. Here is a picture. i.postimg.cc/MTBXwf5K/Screenshot-2020-10-31-100334.jpg What should I do?

  • @aryavratmishra651

    @aryavratmishra651

    3 жыл бұрын

    I fixed the error, but I ended getting a different error. The new error is: java.sql.SQLException: No suitable driver found for jdbc:sqlserver://LAPTOP-5697KK36:1433;databaseName=students at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at net.codejava.sql.JavaConnect2SQL.main(JavaConnect2SQL.java:40) I think what does means is that my JDBC Driver is the wrong version, but I'm not sure. How do I fix this?

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    @@aryavratmishra651 kindly check the guide in this article: www.codejava.net/java-se/jdbc/connect-to-microsoft-sql-server-via-jdbc

  • @bachkhoaCi
    @bachkhoaCi2 жыл бұрын

    vừa nghe được câu đầu tiên biết ngay là người người việt

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    welcome to my Java channel :)

  • @joaquerj9344
    @joaquerj93444 жыл бұрын

    Why do you use Maven?

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    because Maven manages jar files (dependency) very well, save us a lot of time.

  • @joaquerj9344

    @joaquerj9344

    4 жыл бұрын

    @@CodeJava thank you. Great video. Helped a lot

  • @willjce
    @willjce Жыл бұрын

    muchas gracias me ayudo

  • @CodeJava

    @CodeJava

    Жыл бұрын

    you're welcome. Thanks for watching :)

  • @user-bn1ln8vp6g
    @user-bn1ln8vp6g Жыл бұрын

    Can I use vs code as ide

  • @CodeJava

    @CodeJava

    Жыл бұрын

    surely you can use VS Code.

  • @luongtranvan9644
    @luongtranvan96443 жыл бұрын

    thank make

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    You're welcome. Glad it helped.

  • @ChrisT_
    @ChrisT_2 жыл бұрын

    iam getting "The TCP/IP connection to the host Server, port 1433 has failed."

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    make sure SQL server is running and configured to accept incoming TCP/IP connection.

  • @ChrisT_

    @ChrisT_

    2 жыл бұрын

    @@CodeJava So i enabled the TPC/IP coonnection through the SQL Server Configuration Manager and now iam getting a different error. :D The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.

  • @mattiethekoala5619
    @mattiethekoala56192 жыл бұрын

    nice :)

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    Thanks for the visit

  • @gnanathanks5992
    @gnanathanks59923 жыл бұрын

    I don't know how to connect with windows authentication. Pls help me

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Windows authentication: using current Windows user account to log on SQL Server. This mode is for the case both the client and the SQL server are running on the same machine. To connect to SQL Server using authentication, use the JDBC URL like this: jdbc:sqlserver://localhost;integratedSecurity=true; Check the details in my article: www.codejava.net/java-se/jdbc/connect-to-microsoft-sql-server-via-jdbc

  • @houdadouda2232
    @houdadouda22323 жыл бұрын

    Salam brother I have problem the output '' assurer qu'une instance de sql est en cours d'exécution'' please help me

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    is there an instance of SQL server running? Are you connecting to a local or remove SQL server instance? You can check status in Task Manager > Services.

  • @houdadouda2232

    @houdadouda2232

    3 жыл бұрын

    @@CodeJava not local in other pc using ip Adress I check the sql manager and steel the same problem this is the url use'' String dbURL = "jdbc:sqlserver://10. 38.0.23;databaseName=suivi-urbanisme";

  • @iasonotk
    @iasonotk3 жыл бұрын

    respect

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    thanks

  • @yeetboi268
    @yeetboi2682 жыл бұрын

    I can't even login to the database, how? Login failed for user 'root'. ClientConnectionId:077fe851-949f-4f47-8efe-6162b79bcf9d

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    username may be wrong. as SQL server usually has username 'sa'

  • @krishkumar-lg7dm

    @krishkumar-lg7dm

    2 жыл бұрын

    i am also facing the same issue i used sa account to Login pls Suggest

  • @ainaomer
    @ainaomer Жыл бұрын

    This does not work it shows sslhandshakeException

  • @8dfever160
    @8dfever1603 жыл бұрын

    How did you resolve the error "login failed for user "

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    use the correct username and password

  • @Churford1

    @Churford1

    3 жыл бұрын

    You can get further details on connection errors by opening the sql server error logs for the sql server instance through SSMS. From there you should see the reason for the failed login. If there are no errors then you are not even getting to sql server and the connection is erroring before hitting the server.

  • @8dfever160

    @8dfever160

    3 жыл бұрын

    @@Churford1 thanks so much

  • @lequocthinh8992
    @lequocthinh89923 жыл бұрын

    Cam on

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Khong co gi.

  • @Berkeozbeek
    @Berkeozbeek4 жыл бұрын

    I'm currently trying to connect to my localhost and tried to use the code on the codejava website. In my code it is like String url = "jdbc:sqlserver://localhost:1433;databaseName=flustatsworlddb;integratedSecurity=true;"; but it always gives the error. I have a homework for tomorrow. Please help :(

  • @CodeJava

    @CodeJava

    4 жыл бұрын

    what is the error? please post the full exception stack trace here so I can help.

  • @saberasyed4307
    @saberasyed43073 жыл бұрын

    i am unable to know username and possword

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Why? it is specified during installation of SQL Server. Or you need to ask your database administrator.

  • @yogeshambule
    @yogeshambule3 жыл бұрын

    Tcp ip error blocked firewall

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    you need to turn off entire firewall on the server, or add exception to MySQL server.

  • @huyngo2u924
    @huyngo2u9243 жыл бұрын

    cách xóa hàng cũng tương tự vậy phải không anh

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    yes, execute SQL Delete statement. Reference tutorial: www.codejava.net/java-se/jdbc/jdbc-tutorial-sql-insert-select-update-and-delete-examples

  • @officeguru8790
    @officeguru87902 жыл бұрын

    hey pro are you Vietnamese

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    yes, I am.

  • @ben.zamano1866
    @ben.zamano18666 ай бұрын

    anh là người Việt phải không?

  • @CodeJava

    @CodeJava

    6 ай бұрын

    đúng rồi em.

  • @KatRollo
    @KatRollo3 жыл бұрын

    Jump to 27:41 for Maven

  • @ngocvinhtran6957
    @ngocvinhtran6957 Жыл бұрын

    Vietnamese accent :))))))

  • @bpzap1925
    @bpzap19253 жыл бұрын

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    thanks. Glad it helped.

  • @hoangvunguyen2592
    @hoangvunguyen25923 жыл бұрын

    Nam Hà Minh. Việt Nam ?

  • @CodeJava

    @CodeJava

    3 жыл бұрын

    Yes, I am. Welcome to my Java channel. Hope you will get the most out of my videos.

  • @duynhat3473
    @duynhat34732 жыл бұрын

    SO BORING

  • @CodeJava

    @CodeJava

    2 жыл бұрын

    I can understand. Thanks for watching anyway.

Келесі