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
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
4 жыл бұрын
Great to hear that from you, SIR. You motivated younger like me (I'm 37).
Thanks mate. I can now connect to SQL server from Java. I am now immortal
@CodeJava
3 жыл бұрын
Haha, glad it could help.
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
3 жыл бұрын
Glad it was helpful! Thanks for watching :)
Nothing to add. Just a big THANK YOU!
@CodeJava
4 жыл бұрын
Glad you liked it!
Thank you so much! It's very useful.
@CodeJava
4 жыл бұрын
Glad to hear that!
After so many videos found this a useful video, thumbs up (y)
@CodeJava
3 жыл бұрын
Glad it was helpful! Thanks for watching :)
Thanks! Just what I needed.
@CodeJava
4 жыл бұрын
You're welcome!
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
2 жыл бұрын
glad to hear that. Thanks for watching :)
Thank you for the video! Helped me a lot!
@CodeJava
Жыл бұрын
Glad it helped!
thank you so much, Very good explanation, and clear ...
@CodeJava
3 жыл бұрын
You are welcome!
This video helped me alot. Thanks!
@CodeJava
3 жыл бұрын
Glad it helped!
thanks alot sir ,it's very valuable for me :)
@CodeJava
4 жыл бұрын
You are most welcome. Kindly subscribe!
This really helped me out! Thanks
@CodeJava
3 жыл бұрын
Glad it helped!
You made my day. Thank you so much!
@CodeJava
Жыл бұрын
Glad I could help!
thank you so much, you really saved me!!
@CodeJava
Ай бұрын
You're welcome!
thankyou so much , that 's very helpful .
@CodeJava
2 жыл бұрын
Glad it helped.
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
4 жыл бұрын
You're welcome. Glad you found it helpful.
@rishabtyagi6571
4 жыл бұрын
@@CodeJava You are from where...??
@CodeJava
4 жыл бұрын
I'm from Vietnam.
Merci beaucoup monsieur . genial
@CodeJava
4 жыл бұрын
de rien. Also check this video: kzread.info/dash/bejne/Y6R1mJZmltLPqps.html
nhìn giong bạn là biết người việt rồi cảm ơn bạn nhiều
@CodeJava
4 жыл бұрын
Thanks. Subscribe?
@vuongqtvn
4 жыл бұрын
@@CodeJava yes subscribe
Much respect! Thank you!!!!
@CodeJava
3 жыл бұрын
welcome, bro. Thanks for watching.
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
3 жыл бұрын
thanks for the tip. you rock!
@KatRollo
3 жыл бұрын
@@CodeJava You too, thanks for the video. It was my starting point.
thank you so much senor
@CodeJava
2 ай бұрын
You are most welcome. Glad it helped.
THANKYOU SO MUCH :)
@CodeJava
3 жыл бұрын
You're welcome. Glad it helped :)
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)
thank you so much :))
@CodeJava
3 жыл бұрын
You're welcome!
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
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
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
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
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
2 жыл бұрын
@@Raphael2034 yes, I do have one for MySQL here: kzread.info/dash/bejne/lql5zcpxitasd9Y.html
Thank you :)
@CodeJava
3 жыл бұрын
You're welcome!
Em cám ơn anh nhiều !
@CodeJava
3 жыл бұрын
welcome :)
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
3 жыл бұрын
why dblink here? I think it is for Oracle database, not SQL server, right?
Grt learning
@CodeJava
3 жыл бұрын
Glad to hear that
Thanks!
@CodeJava
Жыл бұрын
Welcome!
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
3 жыл бұрын
that means no JDBC driver for SQL server present in the classpath. Check the dependency and jar files
When I connect succeed and send full of file for other computers. How to they also run that program? (Connected sql)
@CodeJava
3 жыл бұрын
I don't understand your question. Could you explain?
Hey, can you please help me in connecting to database with ActiveDirectoryPassword authentication mechanism ?
@CodeJava
2 жыл бұрын
Sorry, I don't know how to work with Active Directory.
cảm ơn bạn nhiều lắm , coi tới phần insert mới biết ng Việt Nam :))
@CodeJava
4 жыл бұрын
You're welcome. Glad it helped. Subscribe?
Excellent and useful video. Too many close-ups. It is hard to read the code.
@CodeJava
4 жыл бұрын
thanks for your feedback.
Nice video :D
@CodeJava
3 жыл бұрын
Thanks! 😁
can you show the same implementations using visual studio code?
@CodeJava
Жыл бұрын
the code will be the same, regardless of IDE.
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
2 жыл бұрын
Isn't it described at 21:50? Execute SQL Insert statement?
Com.microsoft. sqlserverdriver exception tcp/ip port error
How to Connect to Remote SQL Server which requires Window authentications to connect, please keep me posted.
@CodeJava
4 жыл бұрын
You can't connect to remove SQL server using Windows authentication. You must use SQL server authentication.
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
4 жыл бұрын
Sorry, I don't have time to support.
I am getting conenction timeout error. Anyone knows what could be the issue?
@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
4 жыл бұрын
@@CodeJava I have created an instance in localhost.
@CodeJava
4 жыл бұрын
so the database URL may be wrong. Check hostname, port number and database name.
No suitable driver found for jdbc, pls help me
@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
For the connection URL, my server name is LAPTOP-5697KK36, but I don't have an instance name. How do I connect?
@CodeJava
3 жыл бұрын
Open Services manager and you will see the instance name of SQL server.
@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
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
3 жыл бұрын
@@aryavratmishra651 kindly check the guide in this article: www.codejava.net/java-se/jdbc/connect-to-microsoft-sql-server-via-jdbc
vừa nghe được câu đầu tiên biết ngay là người người việt
@CodeJava
2 жыл бұрын
welcome to my Java channel :)
Why do you use Maven?
@CodeJava
4 жыл бұрын
because Maven manages jar files (dependency) very well, save us a lot of time.
@joaquerj9344
4 жыл бұрын
@@CodeJava thank you. Great video. Helped a lot
muchas gracias me ayudo
@CodeJava
Жыл бұрын
you're welcome. Thanks for watching :)
Can I use vs code as ide
@CodeJava
Жыл бұрын
surely you can use VS Code.
thank make
@CodeJava
3 жыл бұрын
You're welcome. Glad it helped.
iam getting "The TCP/IP connection to the host Server, port 1433 has failed."
@CodeJava
2 жыл бұрын
make sure SQL server is running and configured to accept incoming TCP/IP connection.
@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.
nice :)
@CodeJava
2 жыл бұрын
Thanks for the visit
I don't know how to connect with windows authentication. Pls help me
@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
Salam brother I have problem the output '' assurer qu'une instance de sql est en cours d'exécution'' please help me
@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
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";
respect
@CodeJava
3 жыл бұрын
thanks
I can't even login to the database, how? Login failed for user 'root'. ClientConnectionId:077fe851-949f-4f47-8efe-6162b79bcf9d
@CodeJava
2 жыл бұрын
username may be wrong. as SQL server usually has username 'sa'
@krishkumar-lg7dm
2 жыл бұрын
i am also facing the same issue i used sa account to Login pls Suggest
This does not work it shows sslhandshakeException
How did you resolve the error "login failed for user "
@CodeJava
3 жыл бұрын
use the correct username and password
@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
3 жыл бұрын
@@Churford1 thanks so much
Cam on
@CodeJava
3 жыл бұрын
Khong co gi.
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
4 жыл бұрын
what is the error? please post the full exception stack trace here so I can help.
i am unable to know username and possword
@CodeJava
3 жыл бұрын
Why? it is specified during installation of SQL Server. Or you need to ask your database administrator.
Tcp ip error blocked firewall
@CodeJava
3 жыл бұрын
you need to turn off entire firewall on the server, or add exception to MySQL server.
cách xóa hàng cũng tương tự vậy phải không anh
@CodeJava
3 жыл бұрын
yes, execute SQL Delete statement. Reference tutorial: www.codejava.net/java-se/jdbc/jdbc-tutorial-sql-insert-select-update-and-delete-examples
hey pro are you Vietnamese
@CodeJava
2 жыл бұрын
yes, I am.
anh là người Việt phải không?
@CodeJava
6 ай бұрын
đúng rồi em.
Jump to 27:41 for Maven
Vietnamese accent :))))))
@CodeJava
3 жыл бұрын
thanks. Glad it helped.
Nam Hà Minh. Việt Nam ?
@CodeJava
3 жыл бұрын
Yes, I am. Welcome to my Java channel. Hope you will get the most out of my videos.
SO BORING
@CodeJava
2 жыл бұрын
I can understand. Thanks for watching anyway.