Profile

Cover photo
Brandon Fischer
Worked at VA
Attends Rogue Community College
Lives in Grants Pass OR
13 followers|207,799 views
AboutPostsPhotosYouTube

Stream

Brandon Fischer

Dev\Code\Script Related  - 
 
Can anyone help me figure how to get this code to display correctly in a JTextArea? I'm using JDBC, we are able to get the code to send over the string buffer to the main class but the format will not display correctly. The first column will display straight as well as the second but after that the format is all sloppy. The strange thing is that we checked the code output into the command line output area and it will format it correctly when you display it in that area but not in the text area. If anyone can help that would be amazing! 

package pkgfinal;
import java.sql.*;

public class connectURL {
    // Declare the JDBC objects.
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private String URLQuery;
private ResultSetMetaData rsmd;
private StringBuffer sbf;

 public connectURL(String queryString) throws Exception{
              sbf = new StringBuffer();
            //  sbf.delete(0, sbf.length());
                // URLQuery = query;
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Final;integratedSecurity=true;";

       
        // Establish the connection.
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);
            String t =queryString;
            // Create and execute an SQL statement that returns some data.
            stmt = con.createStatement();
                       
            rs = stmt.executeQuery(t);
                        rsmd = rs.getMetaData();
       
            int columnCount = rsmd.getColumnCount ();
            String[] columnLabels = new String[columnCount];
            int[] columnWidths = new int[columnCount];
            for (int i = 1; i <= columnCount; ++i) { 
                columnLabels[i-1] = rsmd.getColumnLabel (i);
                columnWidths[i-1] = Math.max (columnLabels[i-1].length(),
                                              rsmd.getColumnDisplaySize (i)+10);
            }           
                             
                  // Output the column headings.
            for (int i = 1; i <= columnCount; ++i) {
                 sbf.append(format (rsmd.getColumnLabel(i), columnWidths[i-1] ));
                 sbf.append("\t");
                 
            }           
                  sbf.append("\n");           
                // Output a dashed line.
            StringBuffer dashedLine;
            for (int i = 1; i <= columnCount; ++i) {
                for (int j = 1; j <= columnWidths[i-1]; ++j)
                    
                 sbf.append("-");
                 sbf.append("  \t");
                 
            }
                  sbf.append("\n");   
                       
              // Iterate throught the rows in the result set and output
            // the columns for each row. 
            while (rs.next ()) {
                for (int i = 1; i <= columnCount; ++i) {
                    String value = rs.getString (i);
                    if (rs.wasNull ())
                        value = "<null>";
                     sbf.append(format (value, columnWidths[i-1]));
                     sbf.append("     \t \t \t        ");
                }
                sbf.append("\n");
            }      
            
}
       public String toString(){
      
         return  sbf.toString();     
       }  

  // Format a string so that it has the specified width.
  
       private static String format (String s, int width)
    {
        String formattedString;

        // The string is shorter than specified width,
        // so we need to pad with blanks.
        if (s.length() < width) {
            StringBuffer buffer = new StringBuffer (s);
            for (int i = s.length(); i < width; ++i)
                buffer.append (" ");
            formattedString = buffer.toString();
        }

        // Otherwise, we need to truncate the string.
        else
            formattedString = s.substring (0, width);

        return formattedString;
    }
         
}
1
Brandon Fischer's profile photoskooter Martin's profile photo
10 comments
 
It's java II at my college. 
Add a comment...

Brandon Fischer

Discussion  - 
 
Can anyone help me figure how to get this code to display correctly in a JTextArea? I'm using JDBC, we are able to get the code to send over the string buffer to the main class but the format will not display correctly. The first column will display straight as well as the second but after that the format is all sloppy. The strange thing is that we checked the code output into the command line output area and it will format it correctly when you display it in that area but not in the text area. If anyone can help that would be amazing! 

package pkgfinal;
import java.sql.*;

public class connectURL {
    // Declare the JDBC objects.
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private String URLQuery;
private ResultSetMetaData rsmd;
private StringBuffer sbf;

 public connectURL(String queryString) throws Exception{
              sbf = new StringBuffer();
            //  sbf.delete(0, sbf.length());
                // URLQuery = query;
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Final;integratedSecurity=true;";

       
        // Establish the connection.
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);
            String t =queryString;
            // Create and execute an SQL statement that returns some data.
            stmt = con.createStatement();
                       
            rs = stmt.executeQuery(t);
                        rsmd = rs.getMetaData();
       
            int columnCount = rsmd.getColumnCount ();
            String[] columnLabels = new String[columnCount];
            int[] columnWidths = new int[columnCount];
            for (int i = 1; i <= columnCount; ++i) { 
                columnLabels[i-1] = rsmd.getColumnLabel (i);
                columnWidths[i-1] = Math.max (columnLabels[i-1].length(),
                                              rsmd.getColumnDisplaySize (i)+10);
            }           
                             
                  // Output the column headings.
            for (int i = 1; i <= columnCount; ++i) {
                 sbf.append(format (rsmd.getColumnLabel(i), columnWidths[i-1] ));
                 sbf.append("\t");
                 
            }           
                  sbf.append("\n");           
                // Output a dashed line.
            StringBuffer dashedLine;
            for (int i = 1; i <= columnCount; ++i) {
                for (int j = 1; j <= columnWidths[i-1]; ++j)
                    
                 sbf.append("-");
                 sbf.append("  \t");
                 
            }
                  sbf.append("\n");   
                       
              // Iterate throught the rows in the result set and output
            // the columns for each row. 
            while (rs.next ()) {
                for (int i = 1; i <= columnCount; ++i) {
                    String value = rs.getString (i);
                    if (rs.wasNull ())
                        value = "<null>";
                     sbf.append(format (value, columnWidths[i-1]));
                     sbf.append("     \t \t \t        ");
                }
                sbf.append("\n");
            }      
            
}
       public String toString(){
      
         return  sbf.toString();     
       }  

  // Format a string so that it has the specified width.
  
       private static String format (String s, int width)
    {
        String formattedString;

        // The string is shorter than specified width,
        // so we need to pad with blanks.
        if (s.length() < width) {
            StringBuffer buffer = new StringBuffer (s);
            for (int i = s.length(); i < width; ++i)
                buffer.append (" ");
            formattedString = buffer.toString();
        }

        // Otherwise, we need to truncate the string.
        else
            formattedString = s.substring (0, width);

        return formattedString;
    }
         
}
1
Brandon Fischer's profile photo
 
Figured it out! Thanks. Just changed the font to MONOSPACED. For some reason those other fonts mess up the format output. 
Add a comment...

Brandon Fischer

commented on a video on YouTube.
Shared publicly  - 
 
Thanks! Best video that I could find. 
1
Brandon Fischer's profile photo
 
By the way you sound like Vince Vaughn.
Add a comment...
 
This video will show you how to connect to a local database Microsoft SQL server database using Java and the NetBeans IDE.
1
Add a comment...

Brandon Fischer

commented on a video on YouTube.
Shared publicly  - 
 
What IDE is he using? 
1
Brandon Fischer's profile photoTrevor Page's profile photo
2 comments
 
I've been using net beans and this looks legit. It makes your set and get method for you!? That's awesome. That will save me some fat finger time. Lol 
Add a comment...

Brandon Fischer

commented on a video on YouTube.
Shared publicly  - 
 
I snapped my iPhone 5 in half. Hope I can get this phone. 
1
Add a comment...
Have him in circles
13 people
steve fischer's profile photo
Kristina Faux's profile photo
D'kyn Fehr's profile photo
Ellie Enns's profile photo
override1960's profile photo
 
Can anyone help me figure how to get this code to display correctly in a JTextArea? I'm using JDBC, we are able to get the code to send over the string buffer to the main class but the format will not display correctly. The first column will display straight as well as the second but after that the format is all sloppy. The strange thing is that we checked the code output into the command line output area and it will format it correctly when you display it in that area but not in the text area. If anyone can help that would be amazing! 

package pkgfinal;
import java.sql.*;

public class connectURL {
    // Declare the JDBC objects.
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private String URLQuery;
private ResultSetMetaData rsmd;
private StringBuffer sbf;

 public connectURL(String queryString) throws Exception{
              sbf = new StringBuffer();
            //  sbf.delete(0, sbf.length());
                // URLQuery = query;
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Final;integratedSecurity=true;";

       
        // Establish the connection.
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);
            String t =queryString;
            // Create and execute an SQL statement that returns some data.
            stmt = con.createStatement();
                       
            rs = stmt.executeQuery(t);
                        rsmd = rs.getMetaData();
       
            int columnCount = rsmd.getColumnCount ();
            String[] columnLabels = new String[columnCount];
            int[] columnWidths = new int[columnCount];
            for (int i = 1; i <= columnCount; ++i) { 
                columnLabels[i-1] = rsmd.getColumnLabel (i);
                columnWidths[i-1] = Math.max (columnLabels[i-1].length(),
                                              rsmd.getColumnDisplaySize (i)+10);
            }           
                             
                  // Output the column headings.
            for (int i = 1; i <= columnCount; ++i) {
                 sbf.append(format (rsmd.getColumnLabel(i), columnWidths[i-1] ));
                 sbf.append("\t");
                 
            }           
                  sbf.append("\n");           
                // Output a dashed line.
            StringBuffer dashedLine;
            for (int i = 1; i <= columnCount; ++i) {
                for (int j = 1; j <= columnWidths[i-1]; ++j)
                    
                 sbf.append("-");
                 sbf.append("  \t");
                 
            }
                  sbf.append("\n");   
                       
              // Iterate throught the rows in the result set and output
            // the columns for each row. 
            while (rs.next ()) {
                for (int i = 1; i <= columnCount; ++i) {
                    String value = rs.getString (i);
                    if (rs.wasNull ())
                        value = "<null>";
                     sbf.append(format (value, columnWidths[i-1]));
                     sbf.append("     \t \t \t        ");
                }
                sbf.append("\n");
            }      
            
}
       public String toString(){
      
         return  sbf.toString();     
       }  

  // Format a string so that it has the specified width.
  
       private static String format (String s, int width)
    {
        String formattedString;

        // The string is shorter than specified width,
        // so we need to pad with blanks.
        if (s.length() < width) {
            StringBuffer buffer = new StringBuffer (s);
            for (int i = s.length(); i < width; ++i)
                buffer.append (" ");
            formattedString = buffer.toString();
        }

        // Otherwise, we need to truncate the string.
        else
            formattedString = s.substring (0, width);

        return formattedString;
    }
         
}
1
Brandon Fischer's profile photo
 
Figured it out! Thanks. Just changed the font to MONOSPACED. For some reason those other fonts mess up the format output. 
Add a comment...

Brandon Fischer

Discussion  - 
 
Can anyone help me figure how to get this code to display correctly in a JTextArea? I'm using JDBC, we are able to get the code to send over the string buffer to the main class but the format will not display correctly. The first column will display straight as well as the second column in the JTextArea but after that the format is all sloppy. The strange thing is that we checked the code output into the command line output area and it will format it correctly when you display it in that area but not in the text area. If anyone can help that would be amazing! 

package pkgfinal;
import java.sql.*;

public class connectURL {
    // Declare the JDBC objects.
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private String URLQuery;
private ResultSetMetaData rsmd;
private StringBuffer sbf;

 public connectURL(String queryString) throws Exception{
              sbf = new StringBuffer();
            //  sbf.delete(0, sbf.length());
                // URLQuery = query;
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Final;integratedSecurity=true;";

       
        // Establish the connection.
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);
            String t =queryString;
            // Create and execute an SQL statement that returns some data.
            stmt = con.createStatement();
                       
            rs = stmt.executeQuery(t);
                        rsmd = rs.getMetaData();
       
            int columnCount = rsmd.getColumnCount ();
            String[] columnLabels = new String[columnCount];
            int[] columnWidths = new int[columnCount];
            for (int i = 1; i <= columnCount; ++i) { 
                columnLabels[i-1] = rsmd.getColumnLabel (i);
                columnWidths[i-1] = Math.max (columnLabels[i-1].length(),
                                              rsmd.getColumnDisplaySize (i)+10);
            }           
                             
                  // Output the column headings.
            for (int i = 1; i <= columnCount; ++i) {
                 sbf.append(format (rsmd.getColumnLabel(i), columnWidths[i-1] ));
                 sbf.append("\t");
                 
            }           
                  sbf.append("\n");           
                // Output a dashed line.
            StringBuffer dashedLine;
            for (int i = 1; i <= columnCount; ++i) {
                for (int j = 1; j <= columnWidths[i-1]; ++j)
                    
                 sbf.append("-");
                 sbf.append("  \t");
                 
            }
                  sbf.append("\n");   
                       
              // Iterate throught the rows in the result set and output
            // the columns for each row. 
            while (rs.next ()) {
                for (int i = 1; i <= columnCount; ++i) {
                    String value = rs.getString (i);
                    if (rs.wasNull ())
                        value = "<null>";
                     sbf.append(format (value, columnWidths[i-1]));
                     sbf.append("     \t \t \t        ");
                }
                sbf.append("\n");
            }      
            
}
       public String toString(){
      
         return  sbf.toString();     
       }  

  // Format a string so that it has the specified width.
  
       private static String format (String s, int width)
    {
        String formattedString;

        // The string is shorter than specified width,
        // so we need to pad with blanks.
        if (s.length() < width) {
            StringBuffer buffer = new StringBuffer (s);
            for (int i = s.length(); i < width; ++i)
                buffer.append (" ");
            formattedString = buffer.toString();
        }

        // Otherwise, we need to truncate the string.
        else
            formattedString = s.substring (0, width);

        return formattedString;
    }
         
}
1
Brandon Fischer's profile photoCreepers Tnt Pow's profile photoMarco Dörfliger's profile photo
3 comments
 
Yeah you need to use a fixed-width font. 
Add a comment...

Brandon Fischer

Service Questions  - 
 
Has anyone had this problem before? It feels like it's locking up on one side and the tires are skidding when I put the truck in 4Lo or 4ish. The damn wheels feel like they are going to fall off on that side. 
1
Add a comment...
 
Can anyone help me? I'm  trying to make a front end Java program that connects to my Microsoft SQL server 2012 database. Everything I'm finding online needs me to connect the the server through internet or use JDBC, which again I think you need to connect through a server online.  
1
Neil L's profile photoBrandon Fischer's profile photo
29 comments
Neil L
 
Looking forward to the video ;-)
Add a comment...

Brandon Fischer

commented on a video on YouTube.
Shared publicly  - 
 
How would I access my database from outside local network?  
1
Brandon Fischer's profile photoSixFive's profile photo
3 comments
SixFive
+
1
2
1
 
It can do, so you will need to take appropriate network and server steps to ensure only SQL is available.

In a production environment (ideal world) SQL should not be accessible to the public internet, only to the application server that is running code to access the data.
Add a comment...

Brandon Fischer

Discussion  - 
 
Anyone have a better idea how to process this two dimensional array(Needs to be a two dimensional array) ? I got it to work and total up the columns but I just feel like I shouldn't have to create a variable to store the totals of each of the columns. Like I could just output them but I can't think of how.
6
3
Jonas Bergstedt's profile photoAditya Mishra's profile photoJ. Cesar L. Morales's profile photoPhillip Couto's profile photo
9 comments
 
int[] columnsTotal = new int[5];
for(int i = 0; i < 4; i++)
  for(int j = 0; j < 5; j++)
    columnsTotal[j] += arrayOne[i][j];
for(int i = 0; i < 5; i++)
  System.out.println("The colum total is" + columnsTotal[i]);
Add a comment...
People
Have him in circles
13 people
steve fischer's profile photo
Kristina Faux's profile photo
D'kyn Fehr's profile photo
Ellie Enns's profile photo
override1960's profile photo
Education
  • Rogue Community College
    present
    BS/ Transfer - SOU (Computer Network Security and System Information Assurance)
  • Grants Pass High School
    1999 - 2003
Basic Information
Gender
Male
Looking for
Networking
Work
Occupation
Full Time Student
Skills
Computer Network Security, Database Management, Computer Hardware, Java, Java Script, HTML, CSS, SQL.
Employment
  • VA
    Work Study, 2012 - 2013
    Receptionist • Answered, screened and directed inbound phone calls. • Handled general requests for information and data. • Maintained and organized sensitive client files.
  • USN
    Operation Specialist, 2007 - 2012
    Operations Lead Project Manager • Managed and directly supervised a division of 26 while at 80% manning. • Scheduled all short and long term company maintenance; conceived, developed, and instituted a robust schedule using calculated combinations of logistics, personnel and maintenance resources to optimize output. • Sought as top mentor within company; goal-oriented team player recognized for strong communication skills. Fitness Director and Trainer • Lead weekly fitness sessions for over 300 company employees; directly managed fitness standards and personally entered and verified accuracy of database for 55 employees. • Ambassador of America hospitality and culture during joint operations with foreign nations. Data Exchange Specialist • Utilized advanced communications technology to build and coordinate massive tactical data exchange and networking between over a dozen nations in support of deployment counter-piracy missions. • Provided identification data critical to national security to top decision-makers… • Organized and briefed top company executives and their staff of 30+ tacticians daily to direct company coordination while performing in multi-national deployment operations; critical to data exchange between over a dozen nations in support of counter-piracy operations. • Managed Complicated Multi-Network Architectures, including directing, trouble shooting of 20+ warships.
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
Grants Pass OR
Previously
Everett WA
Links