First of all, You will need to add a jar file to your project library as SQL Server 2000 Driver for JDBC Service. My target is SQL Server 2000, it will require the jar file called “sqljdbc4.jar”. This is not supported on Microsoft website now, you can download it here. For other versions of SQL Server, here is the link of SQL Server 2000 Driver for JDBC Service.
The following is the code for connection MS SQL Server and select some records from a testing table.
import java.sql.DriverManager; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection("jdbc:sqlserver://HOSP_SQL1.company.com;user=name;password=abcdefg;database=Test"); System.out.println("test"); Statement sta = conn.createStatement(); String Sql = "select * from testing_table"; ResultSet rs = sta.executeQuery(Sql); while (rs.next()) { System.out.println(rs.getString("txt_title")); } } } |
bata do bhai punay milega
lo kallo bt
kamal krte ho pandey ji khud k question ka khud h answer de rahe ho
vidhya se pucho usko jada ata h
toh nacho tm jake hamara toh ni chala
tumhe to aata hai sikha sakte ho
hm to ni sikha re kal lo jo krna h
aage jao baba hm kyo example de
mujhe bhi sikha do
lo kallo bt , hm kyo sikhaye tmko
Mujhe b sikha do , meko ni ata ye Please Help me
bhai kahi aur pucho
yes very interesting question i also dont know
How Can we fetch data For a given Field From mysql to a combobox..
It works 🙂 Simple is best, thanks you!
W3Schools Demo
Resize this responsive page!
London
London is the capital city of England.
It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
Paris
Paris is the capital and most populous city of France.
Tokyo
Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.
try {
Class.forName(“com.mysql.jdbc.Driver”);
connection = DriverManager.getConnection(
“jdbc:mysql://HOST:port_number/DB_name”,”DB_username”, “DB_pass”);
st = connection.createStatement();
rs = st.executeQuery(“SELECT * FROM table name WHERE id = 1”);
} catch (Exception e) {
System.out.println(“DB error : ” + e);
}
Can you give an example how to connect sql into java
Actually, here’s some info on how to configure the SQL connection using Tomcat https://confluence.atlassian.com/display/DOC/Configuring+a+SQL+Server+Datasource+in+Apache+Tomcat
How about storing the username and password in some config file on the server? I am new to Java, but hopefully it is possible somehow? Could you provide any example? Thanks!
nice and simple basic guide.