I am using windows authenication in sql server 2012. I want to connect java to sql. I have following code (just for example AND Some code is missing as copied from netbeans you know)
public class app extends javax.swing.JFrame { public app() { initComponents(); } @SuppressWarnings("unchecked") private void UserNameActionPerformed(java.awt.event.ActionEvent evt) { String username = UserName.getText(); } private void PasswordActionPerformed(java.awt.event.ActionEvent evt) { String password = Password.getText(); } private void LoginActionPerformed(java.awt.event.ActionEvent evt) { } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new app().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JToggleButton Login; private javax.swing.JPasswordField Password; private javax.swing.JTextField UserName; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration }
Create database ali; use ali; create table Login_System ( Username VARCHAR(50), password VARCHAR(90) ) SELECT * FROM Login_System;
String userName ="username"; String password ="password"; String url ="jdbc:sqlserver://MYPC\\SQLEXPRESS;databaseName=MYDB"; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException ex) { Logger.getLogger(apps.class.getName()).log(Level.SEVERE, null, ex); } Connection conn = DriverManager.getConnection(url, userName, password);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)