Sunday, December 23, 2012

Use JDBC ODBC bridge to read from Excel

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
  public static void main(String[] argvthrows Exception {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String myDB = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=c:/data.xls;"
        "DriverID=22;READONLY=false";
    Connection con = DriverManager.getConnection(myDB, """");
  }
}

Connect to an Oracle database with JDBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {

  public static void main(String[] argsthrows Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(
        "jdbc:oracle:thin:@//server.local:1521/prod""scott""tiger");
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select * from employee");
    while (rset.next()) {
      System.out.println(rset.getString(1));
    }
    stmt.close();
  }
}

   

Creating connection to the MySQL database


import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
  public static void main(String[] argvthrows Exception {
    String driverName = "org.gjt.mm.mysql.Driver";
    Class.forName(driverName);

    String serverName = "localhost";
    String mydatabase = "mydatabase";
    String url = "jdbc:mysql :// " + serverName + "/" + mydatabase; 
                                                                    
    String username = "username";
    String password = "password";
    Connection connection = DriverManager.getConnection(url, username, password);
  }
}

Connecting to a SQLServer Database using the NetDirect JDBC driver

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
  public static void main(String[] argvthrows Exception {
    
    String driverName = "com.jnetdirect.jsql.JSQLDriver"
    Class.forName(driverName);
    
    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase; 
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
  }
}

Create a connection to MS Access database

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
  // private static final String URL = "jdbc:odbc:TestDB";

  private static final String USERNAME = "admin";

  private static final String PASSWORD = "welcome";

  private static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";

  private static final String URL
 = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\Database\\testdb.mdb;}";

  public static void main(String[] argsthrows Exception {

    Class.forName(DRIVER);
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    connection.close();
  }
}

Friday, November 30, 2012

Missing Media in Blogger - Boo!

When someone leaves the University of York, their account is suspended which has the knock on effect that in Blogger your blog posts are written by "Unknown".  You can still see the blog posts.

Worse than that, all the media uploaded by that person also disappears. See this post here.





I'm looking into the Blogger API to see if I can at least find a user's posts and re-create them as someone else as an awful workaround.

I've added an Issue to the Blogger forum.... tumbleweed ... and nobody is interested.

This all comes about because Blogger isn't a "Core App" of Google Apps but it's rubbish. Boo Google!  At least let us be able to transfer ownership of blog posts or something. People regularly come and go at a University and hobbling their blog posts seems ridiculous. This may force us to have to think about using Wordpress ... which will be a shame.

Saturday, November 17, 2012

Code used in video "Java prog#45.Take value from JTable and set it to jDatechooser in Netbeans Java and Sqlite (mysql)"


Here I am providing the downloadable code link of  the Java code I have used in the video
 "Java prog#45.Take value from JTable and set it to jDatechooser in Netbeans Java and Sqlite (mysql)"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below


Date add3=rs.getDate("Update_date");
cmd_date.setDate(add3);


Or if the above code don't work the use the below code 




String add12=rs.getString("Date_Of_Birth");
((JTextField)txt_dob.getDateEditor().getUiComponent()).setText(add12);

-------------------------------------------------------------

Java prog#45.Take value from JTable and set it to jDatechooser in Netbeans Java and Sqlite (mysql)




How can I make a JTable cell do different things on single-click
netbeans java tutorial
Values to be displayed in JTextfield when Clicked on JTable Cells.
Click on JTable Model Updates JTextfield
how can i get value from JTable and set it to textfield.
Show data from JTable in Jtextfield

Code used in video "Java prog#41.How to Use JProgressBar in netbeans java"


Here I am providing the downloadable code link of  the Java code I have used in the video
 "Java prog#41.How to Use JProgressBar in netbeans java"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below is for the ProgressBarActionPerformed method action perform



 private void ProgressBarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        int value =Integer.parseInt(value_int.getText());
        progressbar() ;
        jProgressBar1.setValue(value);
    }  

Code used in video "Java prog#37. Open new jframe and close previous jframe with the easy code in java netbeans"


Here I am providing the downloadable code link of  the Java code I have used in the video
 "Java prog#37. Open new jframe and close previous jframe with the easy code in java netbeans"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below is for the NewActionPerformed  method action perform



  private void NewActionPerformed(java.awt.event.ActionEvent evt) {                                         
      
        
        close();
        Userino_frame s = new Userino_frame();
         s.setVisible(true);
    } 

Code used in video "Java prog#36.How to find maximum,minimum,average values from a table in mysql/sqlite in netbeans"


Here I am providing the downloadable code link of  the Java code I have used in the video
 "Java prog#36.How to find maximum,minimum,average values from a table in mysql/sqlite in netbeans"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below is for the OKActionPerformed  method action perform


private void OKActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
        try{
            String sql="select min(pressure),max(pressure),avg(pressure) from Userinfo";
            pst=conn.prepareStatement(sql);
            rs =pst.executeQuery();
            String add1=rs.getString("min(pressure)");
            min_pr.setText(add1);
            String add2=rs.getString("max(pressure)");
            max_pr.setText(add2);
            String add3=rs.getString("avg(pressure)");
            avg_pr.setText(add3);
            
    }catch(Exception e)
    {
           JOptionPane.showMessageDialog(null, e);

    }finally {
try{
  rs.close();
      pst.close();
    // conn.close();
  }
  catch(Exception e) {
                   }
      } 

        
        
    }        

Code used in video "Java prog#34. Open new JFrame when clicking/selecting an index from the jcombobox in java "


Here I am providing the downloadable code link of  the Java code I have used in the video
 "Java prog#34. Open new JFrame when clicking/selecting an index from the jcombobox in Java "  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below is for the comboselect() method action perform


    public void comboselect(){
 
    if (ComboBox_name.getSelectedItem()=="marry"){
        Userino_frame s = new Userino_frame();
         s.setVisible(true);
 
 
 
    }
    if(ComboBox_name.getSelectedItem()=="julia"){
    LoginJframe l=new LoginJframe();
    l.setVisible(true);
 
 
    }
 
 
 
    } 

Code used in video "Java prog#26.How to print JTable in Java netbeans"

Here I am providing the downloadable code link of  the Java code I have used in the video
 "Java prog#26.How to print JTable in Java netbeans"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINKThis code below is for the cmd_printActionPerformed  method action perform



MessageFormat header = new MessageFormat("Your Header name ");
        MessageFormat footer = new MessageFormat("Page {0,number,integer}      ");
        try {
            jTable1_pumpdata.print(JTable.PrintMode.FIT_WIDTH, header, footer, true, null, true, null);
            //table.print(JTable.PrintMode.FIT_WIDTH, header, null);
           // jTable1_pumpdata.print(JTable.PrintMode.FIT_WIDTH, header, footer);
        } catch (java.awt.print.PrinterException e) {
            System.err.format("Cannot print %s%n", e.getMessage());
        }

Wednesday, November 14, 2012

Ten Tough Collaborative Inbox Questions

I had an interesting meeting with the Law & Management team about the possibility of using a Collaborative Inbox ( which is a kind of Google Group ) rather than our current in-house issue management system.

We went through what they wanted to do when people report problems and they came up with a heap of great questions. With almost all their questions, my answer was, "Ooh, I'll have to look that up and get back tomorrow". Here are the answers.

For the purposes of trying to answer the questions, I am using a Google Collaborative Index Group called "Silly Questions" which has been set up to allow people to email it ( without being a member ) and has two members ( Mike and I ). I will be mailing the group from a test account called "Not Tom".


Q1. Can an issue be automatically given an ID?

This was an based on someone having mailed in an issue, then later calling in and being able to refer easily to the particular issue. An ID can be the quickest way to identify the thread the person is asking about.

Whilst each thread does have an ID, like this SQrl8LBy48Q, that is quite long, impossible to read out reliably and can't be searched for - you'd have to hack the URL to get to the particular thread.

A search for their email like this...

from:csrv644@york.ac.uk

... returns all messages from them. But it is entirely feasible that somebody might have dozens of issues on the go.


Adding a search term (light) from their title helped limit the results (see above) but you can also limit them by adding a tag, assuming the message has been tagged previously.

Note: Thinking deviously, you could potentially tag each new thread with an "ID tag". I looked to see if there was an API for Groups where I might automatically attach an ID to each new incoming message and email the sender with a message with that ID in. There isn't an API to Google Groups! Boo!

Mmm?! I wonder if you could achieve this with the GMail API and AppsScript? You could set up a script to check a given email account once a minute and if there was a new thread, then send a mail replying with an edited subject line containing the new ID. 

You could potentially generate and assign an ID for each incoming message by hand, but more realistically, getting into the practice of tagging issues as they come in might
a. Enable you to find them easier later ( if someone phones in for example )
b. Result, over time, in a useful categorized resource.


Q2. Can an issue be raised on behalf of someone?

A lot of the questions regarding Collaborative Inboxes fall into a "Hang on, what's the simplest way of doing this?" category. In this case, my alter ego, "Not Tom" sent a question to the Silly Questions group and CC'd in Aimee ( see below ).



Although Aimee isn't listed in the view ( above )... when the Real Tom goes to reply, anyone CC'd in is shown in the reply form ( see below ).






Q3. Can you piggy back an issue, being kept in touch with any solution found?

I think this is again handled by being CC'd in to a thread.


Q4. If a thread has been assigned to me, who gets an email when I reply to it? Can other members see what the solution was?


Yes. During this I discovered that if you "Take" a thread and assign it to yourself, everyone else still gets an email, so in the example above, both Mike and Aimee will have a reply. And the thread is visible in the web interface.


Q5. Are tags global?

Yes. If you add a tag to a message, people can search for messages with that tag.

Q6. If a thread is marked as "complete", what happens when someone replies to it again?

The thread is moved back up the lists to the current threads and marked as unread.

NOTE: You can "Lock Replies". If someone then replies to a locked thread, a new thread is created but the reply-er, in this case Aimee, is oblivious to this fact. See below where Aimee has replied to a locked thread.


NOTE: You can mark any reply as a Favourite, by clicking the star icon, but these are personal to you. This is a design mistake in my opinion. They should be global favourites.

NOTE: There is the concept of marking a topic as "Best Answer" but I think that, maybe because I've already participated in my Group that I can't change a question type. This may be a bug. Found it! In Manage > Information > General Information if you select "Allow users to post to the group on the web" then your ability to change your Topic types is disabled. Why I have no idea.

Q7. What's the difference between an Email List and a Collaborative Inbox?

Not much. With each of the "new" Google Groups types ( Web Forum, Q&A discussions ) you pretty much get the same feature set but with a few add-ons and LOTS of configuration options regarding who is/isn't a member, who can post, who can moderate etc.

Q8. Couldn't you create a configurator tool using Google Groups API?

Whilst Google Groups itself doesn't have an API Google Groups Settings API does. And yes. It's a good  ( and challenging idea ). I could imagine two approaches working.

  1. Define a set of discussion types that better match a university's needs ( maybe Seminar Group or Boards of Studies etc ) and create an interface that lets people create those - rather than delving into myriad config items.
  2. Create an "all on one page" list of configuration options but better describe ( with more lengthy and visual documentation ) what the affect of making those changes will be. For example, in the General Information page of settings, you can set your Default topic type to "Discussion" or "Questions" without having any idea how this will change any aspect of your group.


Q9. Why doesn't Gmail allow searching for partial words?

Hang on, that's not a Google Groups question. Because it doesn't. See why and that it's coming real soon ( not ).


Q10. Can Collaborative Inbox Issues be integrated with Footprints?

The notion here was that, if an issue had no resolution then could it be passed into the university issue management system? 

The obvious answer is that a message thread can be forwarded to another email address, so I guess, yes is the answer.

Alternatively, you can "Move" a thread to another Group. I believe this to be groups for which you are a Manager, so were our department to use Collaborative Inbox, we might need to create a new role which would allow a non-member to Move threads into our space. This needs verifying. I think it may be doable.


And Finally...


The hard part about answering these questions is that you need more than three accounts to verify what the public, members, other roles and admins can and can't see and do. Simulating collaboration well is almost impossible. Still, my Silly Questions Group is now looking good ( see left ) and it looks like I need a few more daft questions to go at.

silly-questions-group@york.ac.uk

If anyone at York would like to be a member of the Silly Questions Group so they can trial the Collaborative Inbox features without the bother of setting one up, click the Apply for membership link on this page.







Friday, October 26, 2012

Code used in video "Java prog#24.confermation to detele data (Do you really want to delete ) in NetBeans java GUI"

Here I am providing the downloadable code link of  the java code I have used in the video
 "Java prog#24. confirmation to delete data (Do you really want to delete ) in NetBeans java GUI"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below is for the cmd_deleteActionPerformed method action perform



 private void cmd_deleteActionPerformed(java.awt.event.ActionEvent evt) {                                           
        int p = JOptionPane.showConfirmDialog(null,"Do you really want to delete","Delete",JOptionPane.YES_NO_OPTION );
       if(p==0){
        String sql="delete from Empoyeeinfo where Empoyeeid =?";
        try{
        
            pst=conn.prepareStatement(sql);
            
            pst.setString(1, txt_Empoyeeid.getText());
            
            pst.execute();
            JOptionPane.showMessageDialog(null, "Deleted");
        
        }catch(Exception e){
        
         JOptionPane.showMessageDialog(null, e);
        
        }
        Update_table();
       }
    }   

Code used in video "Java prog#23.How to open any document e.g .pdf, .doc ,.png file from By a jbutton or jmanu NetBeans"

Here I am providing the downloadable code link of  the java code I have used in the video
 "Java prog#23.How to open any document e.g .pdf, .doc ,.png file from By a jbutton or jmanu NetBeans"  of my YouTube channel ProgrammingKnowledge

Click Link to watch the video LINK

This code below is for the HelpActionPerformed method action perform


  private void HelpActionPerformed(java.awt.event.ActionEvent evt) {                                           
        
              try                                      //try statement
        {
                  Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+"C:\\Users\\FilePath\\Frequently Asked Questions.pdf");
                  
                  
        } catch (Exception e)                    //catch any exceptions here
       {
            JOptionPane.showMessageDialog(null,"Error");  //print the error
       }

        
        
        
    } 

Blog Archive

 

© 2013 Klick Dev. All rights resevered.

Back To Top