Swing connection using sql
I am assuming you want to connect MySQL to Java. For this you need Java java connector
Link 1 Link 2 Complete tutorial, but long :)
Please add additional information. Therefore, we can help you more.
source to share
This link has an exact solution to your question.
Simple Java Swings and Mysql login application Swing application for login validation. You need to download "MySql Connector for Java" (aka JConnector) from http://dev.mysql.com/downloads/connector/j / Once downloaded, place the mysql_connector.jar file in your project folder. Use some IDE like Eclipse or other.
source to share
The best link I can give you is
https://drive.google.com/open?id=0B36ZqeHukmpeZWZLRUhxb1FJclU . This ppt helped me connect swing from sql.
I have some code written that connects sql to swing. There is also a detail logging function that tells you how to use sql with a swing.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import javax.swing.AbstractButton;
import javax.swing.JOptionPane;
public class Database {
static String JDBC_DRIVER,DB_URL;
String USER,PASS;
Connection conn;
Statement stmt;
public Database()
{
// JDBC driver name and database URL
JDBC_DRIVER = "com.mysql.jdbc.Driver";
DB_URL = "jdbc:mysql://localhost:3306";
USER = "root";
PASS = "anshtiger";
conn = null;
stmt = null;
ResultSet rs=null;
ResultSet rs1=null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sq;
sq = "create database if not exists AIRLINE";
stmt.execute(sq);
System.out.println("Creating statement...");
String sql="use AIRLINE";
stmt.execute(sql);
}catch(SQLException se1){ //Handle errors for JDBC
se1.printStackTrace();
}catch(Exception e){ //Handle errors for Class.forName
e.printStackTrace();
}
}
public void signupdetail(String userid, String pass2, String question, String answer, String fname, String lname,
String gender, String string, String martial, String email,
String mobileno, String nationality, String address, String city, String state, String country, String pincode){
{
try{
String sq1 = "create table if not exists customerdetail(userid varchar(20) unique, primary key(userid),password varchar(20),question varchar(100),answer varchar(30),fname varchar(20),lname varchar(20),gender varchar(10) ,dob varchar(20),martialstatus varchar(10),emailid varchar(30),mobileno varchar(10),nationality varchar(15),address varchar(50),city varchar(15),state varchar(20),country varchar(20),pincode varchar(8))";
stmt.execute(sq1);
System.out.println("Creating statement...");
String sql2="insert into customerdetail values('"+userid+"','"+pass2+"','"+question+"','"+answer+"','"+fname+"','"+lname+"','"+gender+"','"+string+"','"+martial+"','"+email+"','"+mobileno+"','"+nationality+"','"+address+"','"+city+"','"+state+"','"+country+"','"+pincode+"')";
stmt.executeUpdate(sql2);
stmt.close();
conn.close();
}catch(SQLException se1){ //Handle errors for JDBC
se1.printStackTrace();
}catch(Exception e){ //Handle errors for Class.forName
e.printStackTrace();}
finally{ //finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se3){
se3.printStackTrace();
}//end finally
}
}
}
source to share