Skip to main content

Posts

Showing posts with the label JDBC

JAVA MySQL database connectivity

 JAVA MySQL database connectivity  sample program Below is the the code for Java MySQL database create connection and fetch the data from the database. You need to download Jar or add dependency for java MySQL connector. Please refer following link for the same: https://mvnrepository.com/artifact/mysql/mysql-connector-java Below is the sample code: package test_mysql_connection_demo; import java.awt.BorderLayout; import java.sql.*; import java.util.ArrayList; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; public class Test_mysql_connection_demo { public static void main(String args[]){     Test_mysql tm = new Test_mysql(); tm.conData(); boolean b = tm.exSQL("select * from student"); System.out.println(b); }   } class Test_mysql { public Connection con; void conData() {     try { ...

Java program to get data from sql server and write the data to excel file using apache poi

 Here is a program to to check: 1) the connection with sql server database 2) print the database drivername, driver version, databaseproductname and databaseproduct version 3) get data from sql server  4) print the database result into excel file First add the following dependencies into maven project as we are using the testNG framework and maven project or if you are not using maven project then add respective JAR files into your project. <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>5.0.0</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.4.0</version> <scope>test...