Java Mysql Connectivity Code

import java.sql.DriverManager;
import java.sql.ResultSet;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;



public class jdbcConn {
    private static Connection connect = null;
    private static Statement statement = null;
    private PreparedStatement preparedStatement = null;
    private static ResultSet resultSet = null;
    public static void main(String[] args) throws Exception
    { try {
        // This will load the MySQL driver, each DB has its own driver
        Class.forName("com.mysql.jdbc.Driver");
        // Setup the connection with the DB
        connect = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/emp?"+"user=root");
        statement = (Statement) connect.createStatement();
        // Result set get the result of the SQL query
        resultSet = statement.executeQuery("select * from emp");
      //  writeResultSet(resultSet);
        while (resultSet.next()) {
        String user = resultSet.getString("name");
        System.out.println(user);
        }
               
    } catch (Exception e) {
         System.out.println("error");
        throw e;
    }
       
    }
}



Popular posts from this blog

DDL DML DCL and TCL

Implementation of Calculator using lex and yacc

A Register Allocation algorithm that translates the given code into one with a fixed number of registers.