Results 1 to 2 of 2

Thread: JAVA Mysql

  1. #1
    Dineshmtech is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default JAVA Mysql

    when i execute the following lines in eclipse it shows each and every line is error. I did import the MYsqly-jdbc connection jar file and added with my libraries. But still this shows everything is error. What is the problem exactly ..? Could somebody help me..?


    Thanks in advance


    import java.sql.*;
    public class JDBCexample {
    public static void main(String[] args) throws ClassNotFoundException,
    SQLException {
    String username = "root";
    String password = "root";
    String tablename = "details";
    String fieldname = "name";
    String dbname = "student";
    String query = "SELECT " + name + " FROM " + details + ";";
    /* this chunk of code can appear more or less verbatim */
    /* in your database apps (including JSPs) */
    try{
    String url = "jdbc:mysql://localhost/";
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection(url+dbname, username, password);
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    System.out.println("The contents of field " + name + ":");
    while (rs.next())
    System.out.print(rs.getString(1) + ", ");
    // note that getString anomalously starts counting at 1, not 0
    System.out.println();
    rs.close();
    stmt.close();
    con.close();
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: JAVA Mysql

    If everything is wrong then it's probably a missing semi-colon or misplaced bracket, but without code tags and proper formatting it's impossible to tell.

    Oh, and the errors themselves wouldn't go amiss.

Similar Threads

  1. java mysql
    By seredi in forum New To Java
    Replies: 1
    Last Post: 10-20-2011, 02:25 PM
  2. Java/mysql/jsp
    By samanthamaryhorgan in forum Advanced Java
    Replies: 1
    Last Post: 02-25-2010, 06:28 PM
  3. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  4. java to mysql
    By thamizhisai in forum New To Java
    Replies: 12
    Last Post: 04-28-2008, 07:48 AM
  5. java to mysql
    By thamizhisai in forum Advanced Java
    Replies: 1
    Last Post: 04-26-2008, 08:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •