Date Problem in Java with MySql

Hello
I am using Java with Mysql.I want to enter date in some in my format(YYYY:MM:DD:HH:MM:SS), this thing i have convert using format class and format class return date in String and iwwnat to insert this value in MySQL Table,So i want to know how can i convert String value in Date for Mysql is their inbuild function for converting string into date in mysql.
Regards
Anupam S

Use PreparedStatement and SimpleDateFormat classes
http://onesearch.sun.com/search/onesearch/index.jsp?qt=%2BPreparedStatement+%2BSimpleDateFormat+&qp=siteforumid%3Ajava48&chooseCat=allJava&col=developer-forums&site=dev

Similar Messages

  • Problems conecting java with mysql

    Hi, im workin' with mysql-connector-java-3.1.12 and it work on debug runtime but not when i access the .jar of the project.
    the code of conection is:
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection(url,login,password);
    con.setAutoCommit(false);
    catch (Exception e)
    JOptionPane.showMessageDialog(null,"error en " + e.getMessage());
    there is no problems with code, it works!!, but i don't know what to do about of conection in the .jar
    I apreciate some help with this, Thankkkssss!!!

    Hi, im workin' with mysql-connector-java-3.1.12 and
    it work on debug runtime but not when i access the
    .jar of the project.Huh?
    the code of conection is:
    try
    lass.forName("com.mysql.jdbc.Driver").newInstance();
    con =
    DriverManager.getConnection(url,login,password);
    con.setAutoCommit(false);This is probably wrong. Unnecessary in this case - you aren't doing any writes.
    catch (Exception e)
    OptionPane.showMessageDialog(null,"error en " +
    e.getMessage());This is foolish code. You don't need Swing or a dialog box. You're printing less information than is available. Better to print the entire stack trace.
    is no problems with code, it works!!, Plenty of problems, really, regardless of whether it "works".
    You don't post your URL. That would help.
    but i don't
    know what to do about of conection in the .jar
    I apreciate some help with this, Thankkkssss!!!Put in the CLASSPATH, of course. NOT a system environment variable, either. javac.exe and java.exe ignore it. Use the -classpath option.
    %

  • Can' t connect Java with MySQL

    My goal is to connect Java with MySQL. I found many solutions on Internet, but I always get the same mistake:
    SQLException: No suitable driver
    SQLState: 08001
    VendorError: 0MySQL works fine alone or with php.Only thing left me to think is that the installed versions are not compatible for this mysql-connector-java-5.0.4
    I don't believe that could be a reason.
    Installed versions are:
    Apache Tomcat 5.5.20 Server
    Apache HTTP Server 2.2.4
    PHP 5.2.0
    MySQL 5.2
    jre 1.5.0_11
    jdk1.5.0_11
    Apache Tomacat JK2 connector Version: 1.2.20 File Name: mod_jk-apache-2.2.3.so
    mysql-connector-java-5.0.4
    I also set connector in class path: C:\mysql-connector-java-5.0.4;C:\mysql-connector-java-5.0.4\mysql-connector-java-5.0.4-bin.jar;C:\mysql-connector-java-5.0.4\src\com\mysql\jdbc
    For installation I used manulas from:
    http://apacheguide.org/jsp.php
    http://doc.51windows.net/mysql/?url=/MySQL/ch23s03.html
    Here is also a test code in java:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
       public class Connect
           public static void main (String[] args)
               Connection conn = null;
               try {
        conn =
           DriverManager.getConnection("jdbc:mysql://localhost/first_test" +
                                       "user=monty&password=greatsqldb");
        // Do something with the Connection
    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
       }i'm desperate, please help or tell me someone who'll know the answer.
    Thank You in advance

    hey buddy .. it seems yr code is wrong .. in getconnection () method u should also specify the port ,which u r not doing ...
    the default port for MySQL is 3306 ... see below i am giving you a sample code ... its working fine .. and dont forget to put the MySQL driver jar path in to classpath and also copy the jar into common/lib folder of your tomcat ....
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class MySQLConnectionTest {
         public static void main(String[] args) {
    new MySQLConnectionTest().connTest();
    public void connTest() {
              String tableName = "portfolio"; //change as per setting
              String hostName = "10.81.9.39"; // please change for the target database ip or hostname
              String dbPort = "3306"; //change if not using the default
              String dbName = "tradingsystem"; //change as per the given DB name
              String username = "root"; //change as per setting
              String password = "password"; //change as per setting
              System.out.println("before try");
              Double data=0.0;
         Double data1=0.0;
              try {
    Class.forName("org.gjt.mm.mysql.Driver");
                   System.out.println("before driver manager");
    Connection conn = DriverManager.getConnection("jdbc:mysql://"+hostName+":"+dbPort+"/"+dbName, username, password);
    String query1 = "select * from "+tableName+" where User_id='trader1' and Stock_Type='Equity'";
    System.out.println("quesry1="+query1);
    Statement stmt = conn.createStatement();
    ResultSet rs1 = stmt.executeQuery(query1);
    while(rs1.next())
         System.out.println("hiiiiii for rs1");
         System.out.println(rs1);
         Quantity=(Integer)rs1.getObject(5);
         MarketPrice=(Double) rs1.getObject(8);
         data=Quantity*MarketPrice;
         data1+=data;
         System.out.println("data1="+data1);
         i=0;
    rs1.close();
    stmt.close();
    conn.close();
    } catch (ClassNotFoundException e) {
    e.printStackTrace(System.err);
    } catch (SQLException e) {
    e.printStackTrace(System.err);
    i hope it will work for u...
    cheers,

  • Java with MYSQL in Linux

    i am using JSP in Linux Platform. when i connected to mysql with mysql driver for odbc by using the following code,
    import java.sql.*;
    public class TestMysql
    public static void main(String args[]) {
    try {
              Connection con;
              String connStr = "jdbc:mysql://localhost/test?user=root&password=mysql";
              Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
              System.out.println("OK");
              con = DriverManager.getConnection( connStr );
              System.out.println("Again OK");
    catch( Exception x )
    x.printStackTrace();
    i got the following exception
    OK
    java.sql.SQLException: Error during query: Unexpected Exception: java.io.CharConversionException message given: null
    Nested Stack Trace:
    ** BEGIN NESTED EXCEPTION **
    java.io.CharConversionException
    STACKTRACE:
    java.io.CharConversionException
    at gnu.gcj.convert.Input_iconv.read(char[], int, int) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.String.init(byte[], int, int, java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.String.String(byte[], int, int, java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at com.mysql.jdbc.SingleByteCharsetConverter.SingleByteCharsetConverter(java.lang.String) (Unknown Source)
    at com.mysql.jdbc.SingleByteCharsetConverter.initCharset(java.lang.String) (Unknown Source)
    at com.mysql.jdbc.SingleByteCharsetConverter.getInstance(java.lang.String, com.mysql.jdbc.Connection) (Unknown Source)
    at com.mysql.jdbc.Connection.getCharsetConverter(java.lang.String) (Unknown Source)
    at com.mysql.jdbc.StringUtils.getBytes(java.lang.String, java.lang.String, java.lang.String, boolean, com.mysql.jdbc.Connection) (Unknown Source)
    at com.mysql.jdbc.Buffer.writeStringNoNull(java.lang.String, java.lang.String, java.lang.String, boolean, com.mysql.jdbc.Connection) (Unknown Source)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(com.mysql.jdbc.Statement, java.lang.String, java.lang.String, com.mysql.jdbc.Buffer, int, com.mysql.jdbc.Connection, int, int, boolean, java.lang.String, boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.execSQL(com.mysql.jdbc.Statement, java.lang.String, int, com.mysql.jdbc.Buffer, int, int, boolean, java.lang.String, boolean, boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.configureClientCharacterSet() (Unknown Source)
    at com.mysql.jdbc.Connection.initializePropsFromServer() (Unknown Source)
    at com.mysql.jdbc.Connection.createNewIO(boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.Connection(java.lang.String, int, java.util.Properties, java.lang.String, java.lang.String) (Unknown Source)
    at com.mysql.jdbc.NonRegisteringDriver.connect(java.lang.String, java.util.Properties) (Unknown Source)
    at java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.5.0.0)
    at java.sql.DriverManager.getConnection(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at TestMysql.main(java.lang.String[]) (Unknown Source)
    ** END NESTED EXCEPTION **
    at com.mysql.jdbc.Connection.execSQL(com.mysql.jdbc.Statement, java.lang.String, int, com.mysql.jdbc.Buffer, int, int, boolean, java.lang.String, boolean, boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.configureClientCharacterSet() (Unknown Source)
    at com.mysql.jdbc.Connection.initializePropsFromServer() (Unknown Source)
    at com.mysql.jdbc.Connection.createNewIO(boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.Connection(java.lang.String, int, java.util.Properties, java.lang.String, java.lang.String) (Unknown Source)
    at com.mysql.jdbc.NonRegisteringDriver.connect(java.lang.String, java.util.Properties) (Unknown Source)
    at java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.5.0.0)
    at java.sql.DriverManager.getConnection(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at TestMysql.main(java.lang.String[]) (Unknown Source)
    i have the database, hello.
    The same code works well in Windows, But in Linux, the above exception.
    By using the username root and password mysql , i can connect to mysql directly from the mysql prompt.
    Pls help me..
    I have already put the query 'access denied problem in Mysql' some day before. from the reply, i made some changes in user table(ie. set the password for [email protected].).After this change, this new Exception came..
    The structure of my mysql.user table is
    #     host                         user          password
    1     localhost                    root          68d4f47c49a579c9
    2     localhost.localdomain          root          68d4f47c49a579c9
    3     localhost.localdomain          
    4     localhost          
    Pls help me.
    Edited by: SUMESHBABU_R on Sep 30, 2007 11:36 PM

    Well, at least the trace tells me that this issue is to be tracked back to the core of the MySQL JDBC driver and the Linux's implementation of JVM. It might be worth the effort to post this issue at their website/forum/issuetracker. It might also be worth the effort to tryout the newer MySQL JDBC driver 5.1, as it is written specific for JDK 6.0 (while MySQL JDBC driver 5.0 is targeted at JDK 5.0).

  • Hoe to connect java with mysql 5.0

    I have installed the new Os. in that RHE-5 Os is there, now I want that java can connect ot mysql but , its not able connect with mysql so please guide me.

    1) download mysql connector/J JDBC driver from mysql.com
    2) put the driver jar somewhere where you can put it in the classpath of your application
    3) use proper setup code to connect to the database (search google, tons of examples)
    If at any step you have no clue what I am talking about, you need a good book to help you further.

  • Connectivity java with mySql

    Hi
    Can any one tell me how should i connect my java application with mySql database here is the small code which i written.
    import java.sql.*;
    class tryjdbc
         public static void main(String[] args) throws Exception
         try
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              String connectionURL = "jdbc:mysql://localhost:3306/learn?user=root;password=";
              Connection connection = DriverManager.getConnection(connectionURL, "root", "");
              Statement statement = connection.createStatement();
              ResultSet rs = statement.executeQuery("Select ecode from emp");
              while (rs.next())
                   System.out.println(rs.getString("ecode"));
              catch (Exception e){
                   System.out.println(e);
    Can any one please tell me the error there is no eror in compiling but at run time it gives error
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Thanks in advance
    Dhiraj

    Hi Dhiraj,
    String connectionURL = "jdbc:mysql://localhost:3306/learn?user=root;password=";
    Connection connection = DriverManager.getConnection(connectionURL, "root", "");
    It seems to be your trying to pass twice of your properties details. One from through URL and another from by pasing the parameters on getConnection() method. Better to avoid to use two place in same application. and one more thing I want to confirm r u using "stable" Driver or "alpha" Driver.
    Raju

  • Problem building postfix with mysql

    Hi all,
    I have a sun fire v880 machine running solaris 10, i need to set an email server using postfix+mysql.
    I already installed myql and its working fine. but when trying to build postfix with mysql i get a compliation error, here's wts going on:
    bash-3.00# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/bdb/include -I/opt/mysql/mysql/include -DUSE_SASL_AUTH' 'AUXLIBS=-L/opt/mysql/mysql/lib -R/opt/mysql/mysql/lib -lmysqlclient -lz -lm'
    (echo "# Do not edit -- this file documents how Postfix was built for your machine."; /bin/sh makedefs) >makedefs.tmp
    set +e; if cmp makedefs.tmp conf/makedefs.out; then rm makedefs.tmp; \
    else mv makedefs.tmp conf/makedefs.out; fi >/dev/null 2>/dev/null
    set -e; for i in src/util src/global src/dns src/tls src/xsasl src/milter src/master src/postfix src/smtpstone src/sendmail src/error src/pickup src/cleanup src/smtpd src/local src/trivial-rewrite src/qmgr src/oqmgr src/smtp src/bounce src/pipe src/showq src/postalias src/postcat src/postconf src/postdrop src/postkick src/postlock src/postlog src/postmap src/postqueue src/postsuper src/qmqpd src/spawn src/flush src/verify src/virtual src/proxymap src/anvil src/scache src/discard src/tlsmgr; do \
    (set -e; echo "[$i]"; cd $i; rm -f Makefile; \
    make -f Makefile.in Makefile MAKELEVEL=) || exit 1; \
    done;
    [src/util]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/global]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/dns]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/tls]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/xsasl]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/milter]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/master]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postfix]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/smtpstone]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/sendmail]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/error]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/pickup]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/cleanup]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/smtpd]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/local]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/trivial-rewrite]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/qmgr]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/oqmgr]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/smtp]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/bounce]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/pipe]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/showq]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postalias]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postcat]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postconf]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postdrop]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postkick]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postlock]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postlog]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postmap]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postqueue]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/postsuper]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/qmqpd]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/spawn]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/flush]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/verify]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/virtual]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/proxymap]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/anvil]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/scache]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/discard]
    (cat ../../conf/makedefs.out Makefile.in) >Makefile
    [src/tlsmgr]
    (set -e; echo "# DO NOT EDIT"; /bin/sh ../../makedefs && cat Makefile.in) >Makefile
    rm -f Makefile; (cat conf/makedefs.out Makefile.in) >Makefile
    * Then when i run:
    bash-3.00# /usr/local/bin/make
    The compilation goes on till i get the following error
    "ld: warning: file /opt/mysql/mysql/lib/libmysqlclient.a(libmysql.o): wrong ELF class: ELFCLASS64
    Undefined first referenced
    symbol in file
    mysql_fetch_row ../../lib/libglobal.a(dict_mysql.o)
    mysql_query ../../lib/libglobal.a(dict_mysql.o)
    mysql_error ../../lib/libglobal.a(dict_mysql.o)
    mysql_close ../../lib/libglobal.a(dict_mysql.o)
    mysql_free_result ../../lib/libglobal.a(dict_mysql.o)
    mysql_store_result ../../lib/libglobal.a(dict_mysql.o)
    mysql_init ../../lib/libglobal.a(dict_mysql.o)
    mysql_real_connect ../../lib/libglobal.a(dict_mysql.o)
    mysql_real_escape_string ../../lib/libglobal.a(dict_mysql.o)
    mysql_num_rows ../../lib/libglobal.a(dict_mysql.o)
    mysql_num_fields ../../lib/libglobal.a(dict_mysql.o)
    mysql_escape_string ../../lib/libglobal.a(dict_mysql.o)
    ld: fatal: Symbol referencing errors. No output written to error
    collect2: ld returned 1 exit status
    make: *** [error] Error 1
    make: *** [update] Error 1"
    Please help me with this issue, i use gcc-3.3.2 and used both GNU make and the "make" shipped with solaris, both gave the same result.
    I installed Mysql as a pkg and didn't compile it from source.
    Thanks in advance.

    "ld: warning: file /opt/mysql/mysql/lib/libmysqlclient.a(libmysql.o): wrong ELF class: ELFCLASS64Usually this kind of error is an indication that both 32- and 64-bit object files are being used in building the application. Use all 32-bit objects or 64-bit objects - please do not mix them during compilation.
    If building from scratch is not mandatory for you, you can try installing postfix {and other applications, libraries, ..} with the help of Blastwave's 'pkg-get'. Some instrustions are at: http://technopark02.blogspot.com/2005/06/solaris-installing-appspackages-with.html
    % pkg-get -a | grep postfix
                 postfix 2.2.8,REV=2006.03.13

  • JAVA with MYSQL problem

    i am using jdk1.6.0_02,apache tomcat 5.5.23 ,mysql integrated with redhat linux EE 4 and.mysql connector java 5.0.7.bin.jar.
    look at the the following java program
    import java.sql.*;
    public class TestMysql
    public static void main(String args[])
    try
    String driver = "com.mysql.jdbc.Driver";
    Class.forName( driver );
    String url = "jdbc:mysql://localhost/test";
    DriverManager.getConnection( url, "root", "mysql" );
    catch( Exception x )
    {      x.printStackTrace();
    i got the following exception
    java.sql.SQLException: Access denied for user 'root'@'localhost.localdomain' (us *** password:
    YES)
    at com.mysql.jdbc.SQLError.createSQLException(java.lang.String, java.lang.Str ***, int)
    (Unknown Source)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(int) (Unknown Source)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket() (Unknown Source)
    at com.mysql.jdbc.MysqlIO.secureAuth411(com.mysql.jdbc.Buffer, int, java.lang .String,
    java.lang.String, java.lang.String, boolean) (Unknown Source)
    at com.mysql.jdbc.MysqlIO.doHandshake(java.lang.String, java.lang.String, jav a.lang.String)
    (Unknown Source)
    at com.mysql.jdbc.Connection.createNewIO(boolean) (Unknown Source)
    at com.mysql.jdbc.Connection.Connection(java.lang.String, int, java.util.Prop erties,
    java.lang.String, java.lang.String) (Unknown Source)
    at com.mysql.jdbc.NonRegisteringDriver.connect(java.lang.String, java.util.Pr operties)
    (Unknown Source)
    at java.sql.DriverManager.getConnection(java.lang.String, java.util.Propertie s)
    (/usr/lib/libgcj.so.5.0.0)
    at java.sql.DriverManager.getConnection(java.lang.String, java.lang.String, j
    ava.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at Connect.main(java.lang.String[]) (Unknown Source)
    access denied problem. but the user name and password are correct. i can login to mysql by using
    the same username and password.
    but when connecting through java , i can't ? what is the problem?
    can u help me.?
    actually i am working in JSP. and when i got this problem, i created a small java program for testing.
    here i am submitting the java program.

    friend please put your code inside
       // your code goes here  it will more readable and other can solve it better.
    ==================
    and your problem tells that you must set access permission inside
    mySQL server.
    or try with creating new User with password.
    EnJOY.
    Ghanshyam
    Edited by: Ghanshyam on Sep 28, 2007 4:13 PM

  • MS Access Date problem (from Java program)

    I have written an app. in Java that reads & writes data from a MS Access database.
    I am trying to write an insert class which will add a row of data to one of my database tables - which contains Date fields.
    My problem is that I can update the text fields, but not Date fields - every time I try my program throws an exception:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement
    My simplified code reads as:
    try {
    Statement insertStatement = databaseConnection.createStatement();
    String query = "INSERT INTO myTable(jobId, employeeId, date) VALUES('11', '1', " + "'13/11/2006'" + ");";
    insertStatement.execute(query);
    } //close, etc. etc.
    If I remove the date info from the query, the program executes successfully. I appreciate my problem might be related to the formatting of the date in Access, and if not a 'proper' Java question I give my apologies.
    I have attempted several formats of the date with no success or variation in the exception.
    I am, however, completely stuck and would appreciate any and all help given.
    Regards and thanks
    David

    I have amended my code to use a preparedStatement, but on execution I have the same problem.
    My code is as follows:
    PreparedStatement pstmt = null;
    try {
    String query = "INSERT INTO myTable (jobId, employeeId, date) VALUES(?, ?, ?);";
    pstmt = databaseConnection.prepareStatement(query);
    pstmt.setString(1, "11");
    pstmt.setString(2, "1");
    java.sql.Date sqlDate = getCurrentJavaSqlDate();
    pstmt.setDate(3, sqlDate);
    // execute query, and return number of rows created
    int rowCount = pstmt.executeUpdate();
    System.out.println("rowCount=" + rowCount);
    pstmt.close();
    catch, etc. etc.
    Any ideas or help most welcome
    Regards
    David

  • Problem in Connection with MySql

    Hi,
    i don't know what is th problem with this. i have mysql-jconnector 2.0.14 JDBC Driver and Tomcat-4.0.7. This Program prints nullpointer exception.
    can any one help.
    <%@page import="java.sql.*"%>
    <%
    Connection conn = null;
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    catch(Exception ex)
    ex.printStackTrace();
    try
    conn= DriverManager.getConnection("jdbc:mysql:///sample");
    catch(Exception ex)
    ex.printStackTrace();
    if (conn==null)
    out.write ("Could not create connection");
    else
    out.write ("connection created");
    Statement stmt = conn.createStatement();
    ResultSet rst = stmt.executeQuery("Select * from Admission");
    ResultSetMetaData rstmd = rst.getMetaData();
    int rowcount = 0;
    while (rst.next())
    rowcount++;
    for (int colcount=0;colcount<rstmd.getColumnCount();colcount++)
    out.write (rst.getString(0));
    out.write ("<br>");
    rst.close();
    conn.close();
    %>
    Thanks
    Saran

    Most likely culprit is the rs.next statement. If no records are returned rs will be null and rs.next will through a null pointer exception. try:
    if (rs != null) {
       while (rs.next()) {<p>
    If that doesn't work try blocking off sections of code in seperate try-catch blocks to narrow down where the exception is occuring.

  • Having problems compiling *.java with import javax.servlet.jsp......

    I've been trying to do the tutorials in a book titled Apache Jakarta-Tomcat as part of my introduction to JSP. I'm new to Java but do know the basics. I have on my machine Java 1.3, Java 1.4, Java FrameWorks 2.1 and Jython 2.1 on Win2000 Pro. So enough about my configuration. I have never worked with packages also.
    I downloaded the files from the books site due to the fact I make a lot of typos when hand coding Java (I've become a pretty good debugger of my own code). But everytime I go to compile the *.java I get error messages. So below you will find HelloTag.java and beneath that the error messages that are thrown when I try and compile it. I tested other bits of *.java and have had no problem compiling them. Is there a JSP module I'm missing?
    Am I doing something wrong or am I missing something from my configuration.
    Marijan Madunic
    package chapter2;
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspTagException;
    import javax.servlet.jsp.tagext.TagSupport;
    public class HelloTag extends TagSupport
    public void HelloTag() {
    // Method called when the closing hello tag is encountered
    public int doEndTag() throws JspException {
    try {
    // We use the pageContext to get a Writer
    // We then print the text string Hello
    pageContext.getOut().print("Hello");
    catch (Exception e) {
    throw new JspTagException(e.getMessage());
    // We want to return SKIP_BODY because this Tag does not support
    // a Tag Body
    return SKIP_BODY;
    public void release() {
    // Call the parent's release to release any resources
    // used by the parent tag.
    // This is just good practice for when you start creating
    // hierarchies of tags.
    super.release();
    D:\Java\JDK 1.3\bin>javac HelloTag.java
    HelloTag.java:3: cannot resolve symbol
    symbol : class JspException
    location: package jsp
    import javax.servlet.jsp.JspException;
    ^
    HelloTag.java:4: cannot resolve symbol
    symbol : class JspTagException
    location: package jsp
    import javax.servlet.jsp.JspTagException;
    ^
    HelloTag.java:5: cannot resolve symbol
    symbol : class TagSupport
    location: package tagext
    import javax.servlet.jsp.tagext.TagSupport;
    ^
    HelloTag.java:7: cannot resolve symbol
    symbol : class TagSupport
    location: class chapter2.HelloTag
    public class HelloTag extends TagSupport
    ^
    HelloTag.java:14: cannot resolve symbol
    symbol : class JspException
    location: class chapter2.HelloTag
    public int doEndTag() throws JspException {
    ^
    HelloTag.java:20: cannot resolve symbol
    symbol : variable pageContext
    location: class chapter2.HelloTag
    pageContext.getOut().print("Hello");
    ^
    HelloTag.java:24: cannot resolve symbol
    symbol : class JspTagException
    location: class chapter2.HelloTag
    throw new JspTagException(e.getMessage());
    ^
    HelloTag.java:28: cannot resolve symbol
    symbol : variable SKIP_BODY
    location: class chapter2.HelloTag
    return SKIP_BODY;
    ^
    HelloTag.java:37: cannot resolve symbol
    symbol : variable super
    location: class chapter2.HelloTag
    super.release();
    ^
    9 errors

    Well, it looks like you've not got the servlet development kit JAR on your classpath. I think it'll probably be called servlet.jar on your system. Add that to the classpath if it's not already there.
    Incidentally, you've bumped into one of the areas Java's slightly lenient - declaring a method that looks like a constructor:
    public HelloTag() { }
    public void HelloTag() { }The first is a constructor, the second is a normal method. I'm assuming you intended to have the former instead of the latter.
    Anyway, hope this helps.

  • How make installer java with mySQL database

    How do I create a java installer for windows, because I have a project that uses mySQL database.
    Anyone please help me....

    If you have eg. a desktop application which needs a database, but don't have/ need a database server, which is accessed by several instances of the application (which seems to be the case, otherwise you wouldn't want to install it along with the application), consider an embedded database such as Apache Derby/ Java DB.
    Then all you need is to ship some jars and make sure they are on the classpath.
    If you're using JPA and generate the DB schema, then switching DB vendors should be quite easy. Just reconfigure your persistence.xml.

  • Using java with mysql JDBC

    Hello
    I'm trying to write a program which reads in tab-delimeted text files and then stores the results in a mysql database. The files are roughly 20,000 lines long and can have up to 10 columns, so for the biggest files I have 200,000 pieces of data to be stored seperately in the database.
    I'm currently using the readLine() method of bufferedreader, then using the split function to seperate the string into tokens. The problem is that it seems to be very slow. It is a lot of information, and im not running it on a very fast machine, but even so im sure there must be a more efficient way of acheiving this.
    Here's some of my code:
    BufferedReader in = new BufferedReader(new FileReader("test.res"));
    while((result = in.readLine()) != null) {
    result = in.readLine();
    aLine = result.split("\t");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[0] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[1] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[2] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[3] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[4] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[5] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[6] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[7] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[8] +"')");
    stmt.executeUpdate("INSERT INTO test(words)" + "values('" + aLine[9] +"')");
    I would appreciate any advice thanks.
    PS this is the first time ive tried anything like this so im probably missing something obvious.

    Form the example you have chosen it seems to me, that your table only has one column (words) and that you have multiple value entries for that column in one line of your text file ?!
    That is strange. Normaly I would assume (like the other answers indicate) that you have several columns and that each line in your text file has n values each for a different column.
    Have look at PreparedStatement.
    // the name of your connection is con, you have six columns named col1 to col6 and six entries per line, All six are strings...
    PreparedStatement pstmt = con.prepareStatement("insert into test (col1 , col2 , col3,col4,col5,col6) values( ? , ? , ? , ? , ? , ?)") ;
    BufferedReader in = new BufferedReader(new FileReader("test.res"));
    while((result = in.readLine()) != null) {
       result = in.readLine();
       aLine = result.split("\t");
       for (int i = 0 ; i < 6 ; i++) {
           pstmt.setString((i+1),aLine) ;
    pstmt.executeUpdate() ;
    But this is still not the fastest approach. MySQL supports bulk imports
    Have look at this feature. Maybe the fastest way is to 'convert' the textfile into something like a MySQL dump an than process it using it the MySQL import features.

  • Java with mysql

    if two tables r given, i want a code which should tell tat ,in which table foreign key is available.
    so please kindly help out in this problem.
    is there is any query or code avalible to find out which table as foreign key.

    I don't know if this will have what you're looking for, but that kind of information is available with [url http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DatabaseMetaData.html]DatabaseMetaData. You get it with [url http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Connection.html#getMetaData()]Connection.getMetaData().
    If you're not familiar with JDBC, see this tutorial:
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

  • Best data component to deal with mysql table

    Hi.
    I have an LMS (learning management system) with a lot of info in a mysql dbb with a few tables.I also use a lot of php.
    I was told flash data components aren't the best in the world so what should I do?
    Somebosy mentioned that I should use Flex data components as they were built for this sort of thing and are a lot more powerful. So where do I get one of those for ie: do I have to download anything as I only have Flash Cs5.5. Then how do I get that component into flash?
    Or would it be better to use a third party plugin for displaying tables. Somebody mentioned that excel and its pivot tables are amazing and simple.
    At the end of the day I also want clients to be able to see a dashboard.

    I am looking into various methods.
    Excel has a powerful pivot table which is amazing for tables, graphs etc... in a few drags with no programming.
    My brother uses it in Lloyds bank for number crunching millions of rows so it's even more than I need.
    I don't know of anybody mentioning excel if they use flex ie: maybe I am mixing both worlds. I will look into flex data components as there are tuts on lynda.com and using mxml. Basically a knowledgeable prgm told me I have to know at least as much as the programmer that I subcontract to. Therefore I have been reading my butt off. I am very weak on databases so that's my next field of research.
    THANKS.

Maybe you are looking for