Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NewJFrame extends javax.swing.JFrame {
- Connection con = null;
- ResultSet rs = null;
- PreparedStatement pst = null;
- https://www.youtube.com/watch?v=Z46OHxdEEEI
- https://snag.gy/dFEeaZ.jpg part1
- https://snag.gy/sPYBy6.jpg part 2
- public static void viewTable(Connection con, String dbName)
- throws SQLException {
- Statement stmt = null;
- String query = "select COF_NAME, SUP_ID, PRICE, " +
- "SALES, TOTAL " +
- "from " + dbName + ".COFFEES";
- try {
- stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- String coffeeName = rs.getString("COF_NAME");
- int supplierID = rs.getInt("SUP_ID");
- float price = rs.getFloat("PRICE");
- int sales = rs.getInt("SALES");
- int total = rs.getInt("TOTAL");
- System.out.println(coffeeName + "\t" + supplierID +
- "\t" + price + "\t" + sales +
- "\t" + total);
- }
- } catch (SQLException e ) {
- JDBCTutorialUtilities.printSQLException(e);
- } finally {
- if (stmt != null) { stmt.close(); }
- }
- }
- //Exemplo com JDBC
- import java.sql.*;
- import javax.swing.JOptionPane;
- public class Conexao {
- public static void main(String args[]) {
- try {
- Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
- Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://ivan:1433","sa","");
- Statement stmt = conn.createStatement();
- JOptionPane.showMessageDialog(null, "Conectou!");
- } catch(Exception e) {
- JOptionPane.showMessageDialog(null, e.toString());
- System.out.print(e.toString());
- }
- }
- }
- //Exemplo com JTDS
- import java.sql.*;
- import javax.swing.JOptionPane;
- public class Conexao {
- public static void main(String args[]) {
- try {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://ivan:1433","sa","");
- Statement stmt = conn.createStatement();
- JOptionPane.showMessageDialog(null, "Conectou!");
- } catch(Exception e) {
- JOptionPane.showMessageDialog(null, e.toString());
- System.out.print(e.toString());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement