Mysql + Java

I am writing a SQL statement that should return a record(row), this record is not longer that one column. The SQL statement works fine but I do not know how to put it in a String so that I can print it.
Thank you for your help.

You use a ResultSet to receive the results of the query, use its next() method to move from one record to the next, and its methods like getString() to retrieve the columns from each record. See the tutorial here:
http://java.sun.com/docs/books/tutorial/jdbc/index.html
But you surely didn't post a question like this in the Advanced Language Topics forum? If I didn't understand your question either, please try again.

Similar Messages

  • MySQL + Java doesn't work

    I've been trying to get a connection using MySQL and Java without luck, I've been messing with every solution I have found in google without luck. It worked the last time I used mysql + java a few months ago (in Ubuntu) but now I can't even get a connection.
    MySQL works with PHP, MySQL Administrator and CLI but I just can't get it to work with Java.
    Has anybody been able to run Java applications that use JDBC + MySQL in Arch?
    The stack trace I get is like the following and it changes a little bit if I use different versions of the Connector
    java.sql.SQLException: Server connection failure during transaction.
    Due to underlying exception: 'com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
    ** BEGIN NESTED EXCEPTION **
    java.io.EOFException
    STACKTRACE:
    java.io.EOFException
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1934)
    at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:483)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:992)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2709)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at MySQLConnectTest.main(MySQLConnectTest.java:12)
    Last edited by karmapolice (2007-05-22 20:48:25)

    http://bugs.archlinux.org/task/7256
    Added a bug report

  • XLetview mysql java.lang.notFoundException

    I am programming for TV, I made a basic program that connects to my local database, but when run with the xLetView I get this error when running this line Class.forName ("org.gjt.mm.mysql.Driver ");
    mysql java.lang.notFoundException
    Place the mysql driver in the folder 'jars' of xLetview but nothing works.
    I work with a basic but not with the xLetView.
    Helpme!!!

    There is no such exception. What does the error message really* say? No guessing.

  • MySQL - Java Unable to update

    I am using mysql and when i try to update a table it says....
    java.sql.SQLException: Syntax error or access violation message from
    server: "You have an error in your SQL syntax; check the
    manual that corresponds to your MySQL server version for the right syntax to
    update.....
    my update query is like this...
    "UPDATE Session SET SessionName='"+objSessDet.getTitle()+"' where SessionID="+ConfID;

    my update query is like this...
    "UPDATE Session SET
    SessionName='"+objSessDet.getTitle()+"' where
    SessionID="+ConfID;No, it isn't. That's a fragment of Java code that generates something that is supposed to be an update query. Print the result of that code to see what the query really is.
    But instead of that, use a PreparedStatement instead of that mess (are those single or double quotes, and how many are there, and are there the right number of them?)PreparedStatement ps = conn.prepareStatement("UPDATE Session SET SessionName=? where SessionID=?");
    ps.setString(1, objSessDet.getTitle());
    ps.setInt(2, ConfID); // Or setString()... use the method that matches the column type
    ps.executeQuery();

  • MySQL/Java connection

    I'm experiencing some problems during a connection java/mysql in a debian linux. I've got the message
    SQL Exception: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
    I am using the connector 3.0.8.
    When I enter the shell, everything works fine.
    Here is the code I've used:
    import java.sql.*;
    public class DBTest {
    public static void main(String[] args) {
    try {
    Class.forName ("com.mysql.jdbc.Driver");
    System.out.println("Driver JDBC loaded!");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql");
    } catch (SQLException sqle) {
    System.err.println("SQL Exception: " + sqle.getMessage());
    } catch (Exception e) {
    System.err.println("Exception: " + e.getMessage());
    Thanks!
    Gilmar

    I suspect the problem is the lack of user and pasword. An example of a similar connection I make follows.
    public static Connection openSQLConnection(String connectionDriver, String connectionString) {
      errMsg = "Unable to open SQL connection.";
      // Connection reference
      Connection sqlconn = null;
      try {
        // Load database driver
        Class.forName("com.mysql.jdbc.Driver");
        // Make connection
        sqlconn = DriverManager.getConnection("jdbc:mysql://localhost/passport?user=root&password=");
        catch (ClassNotFoundException cnfex) {showSystemError(errMsg,"openSQLConnection - Class not found exception", cnfex, true);}
        catch (SQLException sqlex) {showSystemError(errMsg,"openSQLConnection - SQL exception", sqlex, true);}
        catch (Exception excp) {showSystemError(errMsg,"openSQLConnection - Remaining exceptions", excp, true);}
        return sqlconn;
    }Note To avoid confusion - my error handler showSystemError will shut down the system idf the connection fails.
    rykk

  • Connection mysql java 2 me

    When i try to connect with the server, it is open a htlm page http://localhost:number of port(server)/Servlet/
    in this page there is written: JSP Page
    it show me this error:
    Could not access the URL through the external browser...open Server and External Tool Settings node and choose a valid browser....
    i tried to do it.... but i didn't resolve my problem!
    Can samebody help me?
    THANKS!
    Ps. it is the code:
    import java.io.*;
    import java.util.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    public class connessioneDB extends MIDlet implements CommandListener {
    private String username;
    private String url =
    "http://localhost:3308/Servlet/servletCon/getConnection";
    private Display display;
    private Command exit = new Command("EXIT", Command.EXIT, 1);;
    private Command connect = new Command("Connect", Command.SCREEN, 1);
    private TextField tb;
    private Form menu;
    private TextField tb1;
    private TextField tb2;
    DB db;
    public connessioneDB() throws Exception {
    display = Display.getDisplay(this);
    public void startApp() {
    displayMenu();
    public void displayMenu() {
    menu = new Form("Connect");
    tb = new TextField("Please input database: ","",30,
    TextField.ANY );
    tb1 = new TextField("Please input username: ","",30,
    TextField.ANY);
    tb2 = new TextField("Please input password: ","",30,
    TextField.PASSWORD);
    menu.append(tb);
    menu.append(tb1);
    menu.append(tb2);
    menu.addCommand(exit);
    menu.addCommand(connect);
    menu.setCommandListener(this);
    display.setCurrent(menu);
    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {}
    public void commandAction(Command command, Displayable screen) {
    if (command == exit) {
    destroyApp(false);
    notifyDestroyed();
    } else if (command == connect) {
    db = new DB(this);
    db.start();
    db.connectDb(tb.getString(),tb1.getString(),tb2.getString());
    public class DB implements Runnable {
    connessioneDB midlet;
    private Display display;
    String db;
    String user;
    String pwd;
    public DB(connessioneDB midlet) {
    this.midlet = midlet;
    display = Display.getDisplay(midlet);
    public void start() {
    Thread t = new Thread(this);
    t.start();
    public void run() {
    StringBuffer sb = new StringBuffer();
    try {
    HttpConnection c = (HttpConnection) Connector.open(url);
    c.setRequestProperty(
    "User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Language","en-US");
    c.setRequestMethod(HttpConnection.POST);
    DataOutputStream os =
    (DataOutputStream)c.openDataOutputStream();
    os.writeUTF(db.trim());
    os.writeUTF(user.trim());
    os.writeUTF(pwd.trim());
    os.flush();
    os.close();
    // Get the response from the servlet page.
    DataInputStream is =(DataInputStream)c.openDataInputStream();
    //is = c.openInputStream();
    int ch;
    sb = new StringBuffer();
    while ((ch = is.read()) != -1) {
    sb.append((char)ch);
    showAlert(sb.toString());
    is.close();
    c.close();
    } catch (Exception e) {
    showAlert(e.getMessage());
    /* This method takes input from user like db,user and pwd and pass
    to servlet */
    public void connectDb(String db,String user,String pwd) {
    this.db = db;
    this.user = user;
    this.pwd = pwd;
    /* Display Error On screen*/
    private void showAlert(String err) {
    Alert a = new Alert("");
    a.setString(err);
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class getConnection extends HttpServlet {
    public void init() {
    public void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    DataInputStream in = new DataInputStream(
    (InputStream)request.getInputStream());
    String db = in.readUTF();
    String user = in.readUTF();
    String pwd = in.readUTF();
    String message ="jdbc:mysql://localhost:3308/"+db+","+user+","+pwd;
    try {
    connect(db.toLowerCase().trim(),user.toLowerCase().trim(),
    pwd.toLowerCase().trim());
    message += "100 ok";
    } catch (Throwable t) {
    message += "200 " + t.toString();
    response.setContentType("text/plain");
    response.setContentLength(message.length());
    PrintWriter out = response.getWriter();
    out.println(message);
    in.close();
    out.close();
    out.flush();
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    doPost(request,response);
    /* This method connects to MYSQL database*/
    private void connect(String db, String user,String pwd)
    throws Exception {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection(
    "jdbc:mysql://localhost:3308/"+db,user,pwd);
    }

    Looks like it's a know bug of Sun ONE Studio:
    http://www.netbeans.org/issues/show_bug.cgi?id=19506
    Don't know if you use it, or have te browser they are refering too...
    Also: where do get this error? From the midlet?

  • Mysql java question?

    Hello,
    I am writing a java program to connect with mysql, the database two tables: order and items.
    In the order the orderNo is a unique value, and appears again the items table for each book ordered.
    Could any advise, if I wanted to delete the orderNo from the order table, and also delete all the records in the items table with the same orderNo, could I achieve this in one sql statement?
    Thanks
    table (order):
    orderNo
    table (items):
    orderNo
    bookname
    quantity
    price

    example for orderNo 2:
    DELETE items,order FROM items,order WHERE order.orderNo=2 and items.orderNo=2Haven't tried this myself, though.
    regards

  • Query from mySQL java.lang.NullPointerException

    I have compile and run the following code but it was an error (java.lang.NullPointerException) when I click the loginButton. Please help me, I don't know how to solve the problem.
    /* * Main.java * * Created on February 19, 2008, 2:50 AM */ package dataprotect; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.swing.*; import javax.swing.JOptionPane; import dataprotect.SecretQuest; public class Main extends javax.swing.JFrame {         /** Creates new form Main */     private Connection connection;     private Statement statement;     private ResultSet rs; /** * * @author  Aiman */     public void connectToDB() {         try {             connection= DriverManager.getConnection("jdbc:mysql://localhost/data_protect?user=root&password=password");             statement = connection.createStatement();                     } catch (SQLException connectException) {             System.out.println(connectException.getMessage());             System.out.println(connectException.getSQLState());             System.out.println(connectException.getErrorCode());             System.exit(1);         }     }     private void init() {         connectToDB();     }             /** Creates new form Main */     public Main() {         initComponents();     }         /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                              private void initComponents() {         loginPanel = new javax.swing.JPanel();         userField = new javax.swing.JTextField();         passLabel = new javax.swing.JLabel();         passField = new javax.swing.JPasswordField();         loginButton = new javax.swing.JButton();         userLabel = new javax.swing.JLabel();         jLabel1 = new javax.swing.JLabel();         registerPanel = new javax.swing.JPanel();         regLabel = new javax.swing.JLabel();         registerButton = new javax.swing.JButton();         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);         setTitle("Data Protector");         loginPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));         passLabel.setText("Password:");         loginButton.setText("Login");         loginButton.addActionListener(new java.awt.event.ActionListener() {             public void actionPerformed(java.awt.event.ActionEvent evt) {                 loginButtonActionPerformed(evt);             }         });         userLabel.setText("Username:");         javax.swing.GroupLayout loginPanelLayout = new javax.swing.GroupLayout(loginPanel);         loginPanel.setLayout(loginPanelLayout);         loginPanelLayout.setHorizontalGroup(             loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, loginPanelLayout.createSequentialGroup()                 .addContainerGap()                 .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                     .addComponent(userLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)                     .addComponent(passLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                 .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                     .addComponent(loginButton)                     .addComponent(passField, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)                     .addComponent(userField, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))                 .addContainerGap())         );         loginPanelLayout.setVerticalGroup(             loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(loginPanelLayout.createSequentialGroup()                 .addContainerGap()                 .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                     .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                     .addComponent(userLabel))                 .addGap(16, 16, 16)                 .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                     .addComponent(passLabel)                     .addComponent(passField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)                 .addComponent(loginButton)                 .addContainerGap())         );         jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));         jLabel1.setText("Data Protector");         registerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());         regLabel.setText("If you are first user? Please register first.");         registerButton.setText("Register");         registerButton.addActionListener(new java.awt.event.ActionListener() {             public void actionPerformed(java.awt.event.ActionEvent evt) {                 registerButtonActionPerformed(evt);             }         });         javax.swing.GroupLayout registerPanelLayout = new javax.swing.GroupLayout(registerPanel);         registerPanel.setLayout(registerPanelLayout);         registerPanelLayout.setHorizontalGroup(             registerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(registerPanelLayout.createSequentialGroup()                 .addGroup(registerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                     .addGroup(registerPanelLayout.createSequentialGroup()                         .addGap(93, 93, 93)                         .addComponent(registerButton))                     .addGroup(registerPanelLayout.createSequentialGroup()                         .addGap(28, 28, 28)                         .addComponent(regLabel)))                 .addContainerGap(18, Short.MAX_VALUE))         );         registerPanelLayout.setVerticalGroup(             registerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, registerPanelLayout.createSequentialGroup()                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                 .addComponent(regLabel)                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                 .addComponent(registerButton)                 .addContainerGap())         );         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());         getContentPane().setLayout(layout);         layout.setHorizontalGroup(             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(layout.createSequentialGroup()                 .addContainerGap(72, Short.MAX_VALUE)                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)                             .addComponent(registerPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                             .addComponent(loginPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                         .addGap(67, 67, 67))                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                         .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)                         .addGap(114, 114, 114))))         );         layout.setVerticalGroup(             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(layout.createSequentialGroup()                 .addContainerGap()                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)                 .addGap(15, 15, 15)                 .addComponent(loginPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                 .addGap(25, 25, 25)                 .addComponent(registerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                 .addGap(27, 27, 27))         );         pack();     }// </editor-fold>                            private void registerButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              // TODO add your handling code here:   //      registerPanel a = new MainFrame();       //      a.show();                        this.setVisible(false);     }                                                  private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                            Connection conn = null;         Statement stmt = null;         ResultSet rs = null;           try {         Statement statement = connection.createStatement();         rs = statement.executeQuery("select username, password from system");                         // create a statement             stmt = conn.createStatement();             // extract data from the ResultSet                 String username = userField.getText();         String password = new String(passField.getPassword());         if(username.equalsIgnoreCase(password)) {             JOptionPane.showMessageDialog(this, "Login Successful");             SecretQuest a = new SecretQuest();             a.show();                        this.setVisible(false);   }         else{     JOptionPane.showMessageDialog(this, "Incorrect username/password combination.", "Login Error", JOptionPane.ERROR_MESSAGE);                 } } catch (Exception e) {             e.printStackTrace();             System.exit(1);         }     /*  try {                 java.sql.Statement s = conn.createStatement();                 java.sql.ResultSet r = s.executeQuery                 ("SELECT username, password FROM system");                 while(r.next()) {                         System.out.println (                                 r.getString("username") + " " +                                 r.getString("password") );                         }         }         catch (Exception e) {                 System.out.println(e);                 System.exit(0);                 } */     }                                                  /**     * @param args the command line arguments     */     public static void main(String args[]) {         java.awt.EventQueue.invokeLater(new Runnable() {             public void run() {                 new Main().setVisible(true);             }         });     }         // Variables declaration - do not modify                        private javax.swing.JLabel jLabel1;     private javax.swing.JButton loginButton;     private javax.swing.JPanel loginPanel;     private javax.swing.JPasswordField passField;     private javax.swing.JLabel passLabel;     private javax.swing.JLabel regLabel;     private javax.swing.JButton registerButton;     private javax.swing.JPanel registerPanel;     private javax.swing.JTextField userField;     private javax.swing.JLabel userLabel;     // End of variables declaration                      }
    I'm using mysql-connector-java-5.0.8 and mysql version 5.0...Any ideas?
    Thanks a lot for your help =)

    Its look can't solve the error..I try to change from:
    // create a statement
            stmt = conn.createStatement();
            // extract data from the ResultSetto this one as you said:
    // create a statement
            stmt = connection.createStatement();
            // extract data from the ResultSetBut the same problem was happen.
    After the error it appear this on output windows of NetBean 5.5:
    at dataprotect.Main.loginButtonActionPerformed(Main.java:198)
            at dataprotect.Main.access$000(Main.java:17)
            at dataprotect.Main$1.actionPerformed(Main.java:76)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6038)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5803)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4410)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2429)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Edited by: Aiman on Feb 25, 2008 5:43 AM

  • Sha1 MYSQL Java Login Form

    I have all my user names and passwords in a MYSQL database. The passwords are encrypted using sha1. Is it possible to have them log into my java application and validate their credentials against this database? If so, can someone point me to a tutorial or guide? I haven't have a lot of luck finding one. Thank you.

    If no salt value was used when encrypting the password in the database it requires the following:
    public boolean confirm(final String username, final String password) {
       final String encryptedDbPassword = getEncryptedDbPassword(username);
       final String encryptedUserPassword = encryptUserPassword(password);
       if( encryptedDbPassword == null ) return false; // No such user.
       return encryptedDbPassword.equals(encryptedUserPassword);
    }

  • Mysql java quizz

    Dear friends,
    I want to make an online quiz system using mysql and java.I am new to Java,however not new to mysql.
    Can anyone guide, please.

    Examine the problem, break it up into manageable pieces and then find out how to do each piece in java. For example, the first problem might be...
    How do I write a simple java program?class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World!");
    }Here is a link to how to do this (and more besides)
    http://java.sun.com/docs/books/tutorial/index.html

  • Mysql/JAVA object

    HI,
    I've started using JAVA to deal with a database (MYSQL), now my problem is to know if i'm doing right by creating over 160 vars (Strings). other servlets will call this class to get those values ...
    if i'm thinking right this mean that i'm killing slowly the server by loading all variables on the memory!!
    what Ineed is to keep accessing those vars while manipulating my object .
    Wha could you suggest please? .
    Regards.

    I have no idea what you're trying (failing) to describe, but it doesn't sound good. Post your code please.

  • Mysql Java how?

    Hello, I wonder what what would be the best solution to have a Java application access a mysql database over the internet? I am a beginner, so please bear with me. I tried using a MM.Mysql driver from http://mmmysql.sourceforge.net/ but couldn't get it to work. Can I use servlets? I have full control over the mysql server.
    Thanks,
    Bertil

    I don't know why this keep happening. I am using JCreator (www.jcreator.com) and set the project's classpath to the location of the mm.mysql-2.0.6.1.jar driver. Location of driver is (C:\Program Files\Xinox Software\JCreator LE\MyProjects\mysql\).
    Compiling works fine, but executing always brings this exeption. Any ideas?
    Unable to load driver.
    java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:120)
    at connect.main(connect.java:13)
    SQLException: No suitable driver
    SQLState: 08001
    VendorError: 0
    Press any key to continue...

  • MySQL, java, & linux

    which one should i download if i have mandrake8.1?
    Binary packages (tar.gz)
    MySQL 3.23.44 Linux (Intel libc6 systems) (7.1M) Download
    MySQL 3.23.42 Linux (Alpha) (8.2M) Download
    MySQL 3.23.44 Linux (IA64) (5.7M) Download
    MySQL 3.23.44 Linux (Sparc) (4.9M) Download
    MySQL 3.23.36 Linux (S/390) (5.6M) Download
    RedHat packages (rpm)
    MySQL 3.23.44 Server (i386) (5.9M) Download
    MySQL 3.23.44 Benchmark/test suites (i386) (687K) Download
    MySQL 3.23.44 Client programs (i386) (1.7M) Download
    MySQL 3.23.44 Libraries and Header files for development (i386) (765K) Download
    MySQL 3.23.44 Client shared libraries (i386) (234K) Download

    which one should i download if i have mandrake8.1?
    Binary packages (tar.gz)
    MySQL 3.23.44 Linux (Intel libc6 systems) (7.1M)
    Download
    MySQL 3.23.42 Linux (Alpha) (8.2M) Download
    MySQL 3.23.44 Linux (IA64) (5.7M) Download
    MySQL 3.23.44 Linux (Sparc) (4.9M) Download
    MySQL 3.23.36 Linux (S/390) (5.6M) Download
    RedHat packages (rpm)
    MySQL 3.23.44 Server (i386) (5.9M) Download
    MySQL 3.23.44 Benchmark/test suites (i386) (687K)
    Download
    MySQL 3.23.44 Client programs (i386) (1.7M) Download
    MySQL 3.23.44 Libraries and Header files for
    development (i386) (765K) Download
    MySQL 3.23.44 Client shared libraries (i386) (234K)
    DownloadWhat hardware are you using? If you are using an Intel-
    based machine, you should use the first one in the list.
    If you are going to do development, you might need the
    second to last one. For client use only, you will need
    the last one.
    Regards,
    Mark

  • Java mysql connectivity

    hi
    i m trying to connect to mysql database through java. i have mysql-java-connector jars file placed in the JAVA_HOME\jre\lib\ext directory.
    now when i try to run this file its starts givin me this error...............
    Exception in thread "main" java.lang.NoClassDefFoundError: Test
    the java file that im running is this............(Test.java)
    import java.sql.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.*;
    class Test
         public static void main(String args[])
              System.out.println("Hello");
              System.out.println("Welcome to the world of java");
              System.out.println("Lets learn java.");
              String url="jdbc:mysql://localhost:3306/database";
              Connection con = null;
              Statement stmt = null;
              ResultSet rs = null;
              String query;
              try {
              try{
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
              catch(Exception e)
                   System.out.println("driver not found"+e.getMessage());
                   con = DriverManager.getConnection (url, "", "");
                   stmt = con.createStatement();
                   query = "select * from test;";
                   ResultSet result = stmt.executeQuery(query);
                   while(result.next())
                   String callNumResult = result.getString("name");
                   System.out.println(callNumResult);
              catch(Exception e)
                   System.out.println("SQLException caught: " + e.getMessage());
              finally {
                   try {
                        if (con != null) con.close();
                   catch (SQLException e) {}
    i have also tried adding that mysql-java connector jar file to the classpath........
    but all in vain.....the error persists.
    plz help me with it.........
    ankur

    hi
    i m trying to connect to mysql database through java.
    i have mysql-java-connector jars file placed in the
    JAVA_HOME\jre\lib\ext directory.That's a terrible place to put them. Only language extensions (e.g., packages that start with javax) belong in there. Put that JAR closer to your application.
    >
    now when i try to run this file its starts givin me
    this error...............
    Exception in thread "main"
    java.lang.NoClassDefFoundError: TestLook at the exception: it's complaining about Test, NOT the MySQL JDBC driver class.
    You obviously don't understand how CLASSPATH works:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html
    I think you have to add the current directory to the CLASSPATH in order to run your Test:
    java -classpath . TestNote the "dot" after -classpath. That tells the class loader to start looking in the current directory. since your Test.java doesn't have a package statement, I'm assuming that Test.class is in the same directory as Test.java.
    >
    >
    >
    the java file that im running is
    this............(Test.java)
    import java.sql.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.*;
    class Test
    public static void main(String args[])
    System.out.println("Hello");
    System.out.println("Welcome to the world of java");
    System.out.println("Lets learn java.");
    String url="jdbc:mysql://localhost:3306/database";
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    String query;
    try {
    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    catch(Exception e)
    System.out.println("driver not found"+e.getMessage());
    con = DriverManager.getConnection (url, "", "");
    stmt = con.createStatement();
    query = "select * from test;";
    ResultSet result = stmt.executeQuery(query);
    while(result.next())
    String callNumResult = result.getString("name");
    System.out.println(callNumResult);
    catch(Exception e)
    System.out.println("SQLException caught: " +
    e.getMessage());
    finally {
    try {
    if (con != null) con.close();
    catch (SQLException e) {}
    i have also tried adding that mysql-java connector jar
    file to the classpath........
    but all in vain.....the error persists.
    plz help me with it.........
    ankur

  • Java connect to mysql

    hi,im new user here.....im also a new java user.......i've just learn how to connect java with mysql,so i download the driver MySQL Connector/J 5.0
    after that,i mport the library to JBulider X.then i got error with my script.
    package database;
    import java.sql.*;
    public class Mysql {
    public static void main(String[] args) {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    catch (Exception e){
    System.err.println("Error Loading driver :" + e.getMessage());
    and then the error are :
    java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:141)
         at database.Mysql.main(Mysql.java:19)
    Exception in thread "main"
    What is that meant ?please someone help me...i need a quick reply......thanxxxsss....

    hello,all.........i just connected to the driver,but now another error come out
    Error SQL Communications link failure due to underlying exception:
    ** BEGIN NESTED EXCEPTION **
    java.net.SocketException
    MESSAGE: java.net.ConnectException: Connection refused: connect
    STACKTRACE:
    java.net.SocketException: java.net.ConnectException: Connection refused: connect
         at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
         at com.mysql.jdbc.Connection.createNewIO(Connection.java:2592)
         at com.mysql.jdbc.Connection.<init>(Connection.java:1509)
         at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
         at java.sql.DriverManager.getConnection(DriverManager.java:512)
         at java.sql.DriverManager.getConnection(DriverManager.java:193)
         at database.Mysql.main(Mysql.java:28)
    ** END NESTED EXCEPTION **
    wat is that mean ?
    this is my script
    package database;
    import java.sql.*;
    public class Mysql {
    public static void main(String[] args) {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
    System.out.println("Loading drivers........");
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    System.out.println("Driver loaded !");
    catch (Exception e){
    System.err.println("Error Loading driver :" + e.getMessage());
    try {
    con = DriverManager.getConnection("jdbc:mysql://localhost/test_db?user=test_admin&password=1234");
    stmt = con.createStatement();
    rs = stmt.executeQuery("select * from `stock`");
    ResultSetMetaData rsmd = rs.getMetaData();
    int nColumn = rsmd.getColumnCount();
    for(int i=1;i<=nColumn;i++){
    System.out.print(rsmd.getColumnName(i) + " | ");
    System.out.print("\n");
    /*while(rs.next()){
    System.out.println(rs.getLong(1) + "\t" + rs.getString(2) + "\t" + rs.getLong(3) + "\t" + rs.getString(4) + "\t"
    + rs.getDouble("price") + "\t" + rs.getInt("supplier") + "\t" + rs.getDate("buy_date"));
    rs.close();
    stmt.close();
    con.close();
    catch (SQLException e){
    System.err.println("Error SQL " + e.getMessage());

Maybe you are looking for

  • Error in Installing Jdev 12C through Generic istaller

    I tried to run the installer. it runs and in the middle i gives an error in copying files. You can view the screen shot of the error here . https://docs.google.com/file/d/0B2uF0CGt8hayWUFRSkpDOHU1NGc/edit?usp=sharing

  • Macbook sound to airport express

    Hi, I have a airport extreme/airport express network setup here where I can listen to itunes through my home stereo. Works great- works so well I want to be able to listen to non itunes sound through the stereo (streaming media, DVD's, etc.) Is this

  • Help!  RAM problem in CS4 on iMac

    Hi all  - I need some assistance.  I have a new 16GB iMAC and am running Photoshop CS4.  I am having a problem with it telling me it can't run functions because it has run out of RAM when the activity monitor is registering total system use of 3.5GB

  • Saving in Lightroom

    What I want to do is export my finished, adjusted picture to a file in order that I can work on it using another product. I have tried to use the export facility but found it was saving the original unchanged document not my updated one. I am using a

  • Need help on my ipod classic

    When my I pod is connected to the computer it says do not disconnect but Itunes will not recongize my ipod but the computer does when i disconnect it from the computer it says ok to disconnect I've tried everything that has been discussed  in the com