Problem connecting to Mysql using JDBC

Hi Everyone,
I am trying to connect Mysql ad java applet and I am using the Mysql jdbc connector.
I Took the mysql-connector-java-5.0.8-bin.jar file and put that in the library of jdk.
Now i used the following code to connect to the database using Netbeans.
package testmysql;
import java.sql.*;
public class Main
public static void main (String[] args)
Connection conn = null;
try
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/rpms";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
catch (Exception e)
System.err.println ("Cannot connect to database server");
finally
if (conn != null)
try
conn.close ();
System.out.println ("Database connection terminated");
catch (Exception e) { /* ignore close errors */ }
But it displays Cannot connect to database server
thoughMysql server is running.
Can anyone tell me wats the prob in this.
thanks

String url = "jdbc:mysql://localhost/rpms";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Is rpms the MySQL database?
Is the database on the default port 3306?
Is the MySQL JDBC JAR file in the classpath of the applet?
newInstance() is not required to be invoked unless using <= JDK 2.0
Replace:
catch (Exception e)
System.err.println ("Cannot connect to database server");
with:
catch (Exception e)
System.err.println (e.getMessage());
Edited by: dvohra09 on Apr 10, 2009 10:54 PM
Edited by: dvohra09 on Apr 10, 2009 10:55 PM
Edited by: dvohra09 on Apr 10, 2009 10:58 PM

Similar Messages

  • Problem connecting to MySQL thro Applet using JDBC

    Hi,
    I'm trying to use an applet to connect to MySQL thro JDBC. The applet, the IE client that loads the HTML, and MySQL all reside on the same machine. But I'm getting the following error:"ClassNotFoundException: com.mysql.jdbc.Driver". But I'm able to connect using a Java application and run and display SQL query results. Any ideas are highly appreciated. Here're are the two pieces of code:
    /****** Java Application *****/
    import java.sql.*;
    public class MySQL_App {
    public static void main(String args[]) {
              String url = "jdbc:mysql://localhost/test";
         try {
                   Class.forName("com.mysql.jdbc.Driver");
         catch(java.lang.ClassNotFoundException e) {
                   System.err.print("ClassNotFoundException: ");
                   System.err.println(e.getMessage());
    /****** Java Applet *****/
    import java.awt.*;
    import javax.swing.*;
    import netscape.javascript.*;
    import java.sql.*;
    public class MySQL_Applet extends JApplet {
         JSObject win;
         public void init() {
              win = JSObject.getWindow(this);
         public void callShowMessage() {
              String url = "jdbc:mysql://" + this.getDocumentBase().getHost() + "/test";
              String[] args = new String[1];
         args[0] = "" ;
         try {
              Class.forName("com.mysql.jdbc.Driver");
         catch(java.lang.ClassNotFoundException e) {
                   args[0] += "ClassNotFoundException " + e.getMessage() ;
         win.call("showMessage", args);
    }

    mmm i, think that may here we've 2 possibles answers:
    1) Did u read about "Applet Security"? my point is that you haven't acces to your local var "path" or "classpath".
    2) Maybe u didn't especificate the MySQl path in ur classpath;
    Check this 2 points

  • Connecting to Oracle using JDBC

    Hi all,
    I am a new to Oracle. I am trying to connect to Oracle using JDBC
    The URL with which I tried to connect was:
    jdbc:oracle:oci8:@myServiceName,user='myLogin',password='myPassword'
    I get an error (ORA-12154)
    - TNS could not resolve service name
    When I use the same userid, password and service and connect thru' SQL*Plus it goes thru'. Is there any parameter which I am missing. Can anyone throw some light on this. I am held up with this issue badly.
    Thanks for all your help and time.
    Regards,
    Latha

    Hi Latha,
    Please try to use thin and add port number.
    m_conn = DriverManager.getConnection("jdbc:oracle:thin:@" + hostURL + ":" + port + ":" + database, user, password);
    Hong
    null

  • Hi i am having problems connecting to internet using ethernet,in the network diagnostics i get all green,except network settings which is orange.i am running mountain lion on intel imac

    hi i am having problems connecting to internet using ethernet,in the network diagnostics i get all green,except network settings which is orange.i am running mountain lion on intel imac

    hi have done as you said plug ethernet straight into computer and into back of router,and worked straight off,i had the the powerline on extention when imac was up stairs,when i had computer down stairs it still would not work with powerlines even on main wall sockets,so they are getting binned,looks like i will have to move router upstairs,just wondering if i got extention wire from back of openreach box to router upstairs```,would it be ok,,the openreach box is next to my only phone socket in house,which is in back kitchen..any advice would be great,

  • Is it possible to connect to mysql using sun.jdbc?

    Is it possible to connect to a mysql database using sun's jdbc:odbc driver?
    I develop a page on the internet that uses mysql. The connection code is placed in a java class. I get the errormessage: "no suitable driver" when I try to connect with jsp/java classes.
    If I use PHP it is ok.
    Code:
    $db = mysql_connect("localhost", "vegg", "nbvv2003");
    mysql_select_db("vegg_timereg",$db);
    $result = mysql_query("SELECT * FROM bruker",$db);The java code is like this:
    java.sql.Connection conn = null;
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    try {
          Class.forName(driver);
          conn = DriverManager.getConnection("jdbc:odbc:vegg_timereg","vegg","nbvv2003");
        catch (SQLException e) {
          out.print("<font color=red>Error:</font> SQLException<br>");
          out.print(e.getMessage());
        catch (ClassNotFoundException e) {
          out.print("<font color=red>Error:</font> Driver not found<br>");
          out.print(e.getMessage());
        catch (Exception e) {
          out.print("<font color=red>Error:</font> Error on initializing<br>");
          out.print(e.getMessage());
        }For me it does not seem like there are any drivers available in java, I've tried the sun.jdbc.odbc.JdbcOdbcDriver and org.gjt.mm.mysql.Driver. The mySql driver is missing, so that is the reason, but I do not get an error message when importing the jdbc:odbc driver.
    I do not have permission to check the setup on the webserver:(
    It runs Apache webserver.

    thx, but I don't seem to get any databases. It works when I run it locally, but on the external webserver it doesn't.
    Database info:
    Name: vegg_timereg
    Place: localhost (root)
    Type: mySQL
    It doesn't seem like the mysql driver is installed on the server, so I have to use jdbc. I do not have any permissions on the server, so I can't check it out myself.
    In PHP this connection works:
    $db = mysql_connect("localhost", "vegg", "nbvv2003");
    mysql_select_db("vegg_timereg",$db); I've tried like this (using java.sql.Driver): Class.forName("java.sql.Driver");
    conn = DriverManager.getConnection("jdbc:localhost/vegg_timereg","username","password");This is really annoying when it's so easy on my machine...

  • Connecting to Oracle using JDBC problem

    When trying to connect using the following few lines:
              String urn = "jdbc:oracle:thin:@localhost:1521:XE";
              Class.forName("oracle.jdbc.driver.OracleDriver");
              Connection _con = DriverManager.getConnection(urn, "user", "pass");
    I get an ArrayIndexOutOfBounds Exception
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
         at oracle.security.o3logon.C1.r(C1)
         at oracle.security.o3logon.C1.l(C1)
         at oracle.security.o3logon.C0.e(C0)
         at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
         at oracle.jdbc.ttc7.O3log.<init>(O3log.java:287)
         at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:227)
         at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:198)
         at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:251)
         at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:224)
         at java.sql.DriverManager.getConnection(Unknown Source)
         at java.sql.DriverManager.getConnection(Unknown Source)
    I am using JDK 1.4, and I installed the Oracle Database 10g Express Edition.
    If anyone has used JDBC before, and knows how this should be done...
    thanks

    Hi All,
    Even im facing similar issues, please advise and help. Details as below,
    System and java spec used:
    Windows Edition : Windows Server 2008 R2 Standard
    System type : 64-bit Operating System
    NetBeansIDE version : 6.1
    JDK Version : 1.6
    DB : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    Connection string: : <root>
    <title>Oracle R12 Prod</title>
    <jdbc-connection-string>jdbc:oracle:thin:<username>/<password>@<host>:<port>:<SID></jdbc-connection-string>
    </root>
    StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
    java.lang.ArrayIndexOutOfBoundsException: 7
    at oracle.security.o3logon.C1.r(C1)
    at oracle.security.o3logon.C1.l(C1)
    at oracle.security.o3logon.C0.c(C0)
    at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
    at oracle.jdbc.ttc7.O3log.<init>(O3log.java:290)
    at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:251)
    at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:252)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:207)
    at db.dbConnect.makeConnection(dbConnect.java:55)
    at org.apache.jsp.rep.rep1_005fgo_jsp._jspService(rep1_005fgo_jsp.java from :222)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:855)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:660)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:578)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:997)
    at org.apache.jsp.rep.rep1_005fgo0_jsp._jspService(rep1_005fgo0_jsp.java from :111)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

  • Connection to mySQL via jdbc

    I'm currently programming a GUI to access a database. Therefore I executed a query, which worked fine. But when I tried to exit my program with
    System.exit(0)my DOS-Prompt crashes without exiting.
    Now I tried it with a kind of minimalistic Connection like that:
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/stock");     
    conn.close();Here the same problem occurs, so it must be the Connection that causes the error.
    If I would exit the program right away after the Connection, that is
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/stock");     
    conn.close();
    System.exit(0);then the program exits properly. Unfortunately it doesn't make any sense to quit the program right after reading the data.
    So, as you can guess, I'm quite confused. I used the same driver and the same database in another program on the same computer, and it works fine. So I'm left totally clueless.
    I'm not using a special programming environment, I just write my code using UltraEdit. I've got installed Java 1.4.0 on my machine.
    Any help is very appreciated
    Martin

    I don't get any.
    It just crashes. There's neither an exception thrown nor any other error msg.

  • Connect to MySQL without JDBC

    Hello to everyone,
    Is there any way i can connect to a MySQL database without using JDBC? My web host does not support Java unless i go and buy a dedicated Server package which costs a small fortune so i am trying to find a work-around solution. Is there any way i can access a database by combining Java (locally) and PHP on server-side to get data out of the database and back to the Java piece of software?
    Thanks to everyone who might see or reply to this post

    Hello deeprave, thanks for replying so quick.
    So i guess this is not the best thing to do then. Please allow me to state my problem clearly . Maybe someone might have an answer to my issue. I want to be able to connect Java software on a web server. As deeprave correctly spotted, this can be done using Sockets. Indeed, i have my program connecting to the server.
    On my website, i ask users to register themselves in the user database (using standard PHP). Users are then able to log in their account and do stuff. This works fine through the browser.
    Issue is at the point where i want my Java software sitting locally on the users machine to be able to connect to the server and authenticate the user. If a user is not registered, the software wont be able to operate (or at least enable user do specific actions). If anyone has any ideas that might help i would be grateful if he/she shares them with me. I am approaching my deadline for submitting my 3rd ear project and i am a bit worried...
    Thanks a lot, and excuse me for the long question

  • Problem connecting to MySQL DB

    I am having a problem connecting to my database with the most basic java code.
    The code I have been using is at bottom of message. It compiles fine, and runs ok too, but does not connect, it gets the Exception and displays the "Canot connect ..." message. From the command line I can use the mysql client with the same user and pass I am using in the program with no problems. Any ideas on something else that might be causing it? I have already downloaded driver and include the paths in the CLASSPATH. Thank you for any help!
    CODE:
    import java.sql.*;
    public class Connect
    public static void main (String[] args)
    Connection conn = null;
    try
    String userName = "testuser";
    String password = "testpass";
    String url = "jdbc:mysql://localhost/test";
    Class.forName ("com.mysql.jdbc.Driver").newInstance ();
    conn = DriverManager.getConnection (url, userName, password);
    System.out.println ("Database connection established");
    catch (Exception e)
    System.err.println ("Cannot connect to database server");
    finally
    if (conn != null)
    try
    conn.close ();
    System.out.println ("Database connection terminated");
    catch (Exception e) { /* ignore close errors */ }

    Thank you so much.
    I tried searching for a while without finding any answers and right after trying printStackTrace the problem becomes so clear. It was a host problem, after adding the appropriate privileges I was able to connect.
    I think printStackTrace will come in handy for any debugging while developing applications.
    Thanks again!

  • Problems connecting to MySql on GoDaddy

    Hi!
    Don't know if it's the right place to ask, but I'm stuck with a problem.
    I've just bought my domain from GoDaddy.com and set a MySql database there. However, when I try to login to the server using the following info my Java application refuses to create a connection.
    String urlDatabase = "jdbc:mysql://mysql server/databasename"; String user = "databasename"; // on godaddy the db and user are the same String password = "mypassword";
    The same code used to connect to the database works clean and smooth on my local machine.
    After I construct the connection string it throws me the following errors:
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1119) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2257) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:784) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:354) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at magenta.model.database.connectionpool.JDCConnectionPool.getConnection(JDCConnectionPool.java:62) at magenta.model.database.connectionpool.JDCConnectionDriver.getConnection(JDCConnectionDriver.java:36) at magenta.main.Main.<init>(Main.java:20) at magenta.main.Main.main(Main.java:39)
    I have to say that in phpmyadmin, from GoDaddy, the user appears to login to a different IP than that where the database is stored.
    It says somenthing like this:
    # Server: testdatabase11.database server.com (IP1 via TCP/IP)
    # User: testdatabase11@IP2
    Don't know if that may be the cause of my problem though.
    I emailed them some hours ago but still didn't get any answer.
    Any help will be highly appreciated!

    I have a similar problem, I have a paid GoDaddy hosting account, ssh is enabled, and I can access the database from a php script run at home so its not an internet issue... I can't figure out what the problem is, but the program is crashing when I get to the createStatement() command... Any ideas anyone?
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class sqltest extends Activity {
                    Connection conn=null;
              try {
                   // from http://help.godaddy.com/topic/319/article/262
                   conn = DriverManager.getConnection(
                                       "jdbc:mysql://profiles.db.1111111.hostedresource.com:3306/dbname",
                                       "dbname", "password");
              } catch (SQLException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
              try {
                   // Create a result set containing all data from mysql_all_table
                   Statement stmt = conn.createStatement();
                   ResultSet rs = stmt.executeQuery("SELECT * FROM *");
    }PS: I'm technically doing this in android, but I think the problem is pure java...

  • Weird Problem calling Stored Procedure using JDBC

    Scenario is..
    I have J2EE application and calling stored procedure using JDBC.
    My application connects to instance "A" of testDB.
    Schema "A" does NOT own any packages/procedure but granted execute on oracle packages/procedures that reside in schema "B" of testDB.
    In java code I call procedure(proc1) in package(pac1) which internally calls procedure(proc2) in package(pac2).
    The problem occurs when procedure pac2.proc2 is modified. After the modification, my java code fails and throws an exception "User-Defined Exception" and I am also getting "ORA-06508: PL/SQL: could not find program unit being called". This clears up only if I bounce the web container. (This doesn't happen if I modify pac1.proc1 and run my application)
    Has any one faced this problem? Please suggest if any thing can be changed in jdbc code to fix this problem.
    Thanks

    Hi,
    I assume these are PL/SQL packages and that the changes are made at the package specification level?
    If so, it looks like you are hitting the PL/SQL dependencies rules. In other words, if the spec of proc2 is changed, then proc1 is invalidated, since proc1 still depends on the old version of proc2's spec. As a result, if you try to run proc1, its spec must either be explicitly rewritten before it could run again or implicitly recompiled first, if the (implicit) recompilation fails, it won’t run.
    Kuassi http://db360.blogspot.com

  • Cannot connect to database using JDBC

    Hello!
    I am trying to connect to my local database using this script:
    import java.sql.*;
    public class test{
    public static void main (String[] args){
      try
        DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
        Statement StmtPersoane = conn.createStatement();
        ResultSet CrsPersoane =StmtPersoane.executeQuery("select p.* from personal p");
        int jMarca = 0;
        while(CrsPersoane.next()){
        jMarca = CrsPersoane.getInt("marca");
        System.out.println(jMarca);
        CrsPersoane.close();
        StmtPersoane.close();
        conn.close();
      catch(SQLException e)
        e.printStackTrace();
    }When compiling i am getting this error: Error(7,58): cannot access class oracle.jdbc.driver.OracleDriver; file oracle\jdbc\driver\OracleDriver.class not found
    I have set a CLASSPATH enviroment variable with value : D:\oracle10g\product\10.1.0\Db_1\jdbc\lib\ojdbc14.jar
    Please provide some hints. Thanks in advace !

    Problem solved with the connection, but now i'm getting another error when i am trying to parse an error. Here is the code a little bit modified:
    import java.sql.*;
    import java.text.*;
    import java.text.ParseException;
    import java.util.*;
    public class test{
    public static void main (String[] args){
      try
        DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
                Statement StmtPersoane;
                StmtPersoane = conn.createStatement();
                ResultSet CrsPersoane =StmtPersoane.executeQuery("select marca from personal");
                int jMarca;
                jMarca = 0;
    java.util.Date dataJava = new java.text.SimpleDateFormat("dd/mm/yyyy").parse("04/10/2006");
    java.sql.Date dataSql = new java.sql.Date(dataJava.getTime());
    System.out.println("Data: "+dataSql);
        System.out.println("Angajatii sunt:"); 
                while(CrsPersoane.next()){
        jMarca = CrsPersoane.getInt("marca");
        System.out.println(jMarca);
        CrsPersoane.close();
        StmtPersoane.close();
        conn.close();
      catch(SQLException e)
        e.printStackTrace();
    }The error:
    Error(24,81): unreported exception: java.text.ParseException; must be caught or declared to be thrown
    Any ideas ?

  • Connect Flat files using jdbc

    Hi,
    I have a problem with connecting flat files(.txt, .xml, .csv, .xls, etc...) which is existing in application it's self, using jdbc connection.
    After searching I found some suggestions below.
    1)xlsql
    2)JDO
    I tried with first one (xlsql), below is the process. First create core java project and load the jar files which is from xlsql. below is the code
    Class.forName("com.nilostep.xlsql.jdbc.xlDriver");
    final String dir = System.getProperty("user.dir")+"\\db\\xl";
    conn = DriverManager.getConnection("jdbc:nilostep:excel:/"+dir);
    Statement stmt = con.createStatement();
    String sql = "select * from Sheet1$";
    ResultSet rs = stmt.executeQuery(sql);
    if(rs.next()){
    System.out.println(rs.getString(1));
    }else{
    System.out.println("nodata....");
    It is saying Sheet1$ table not existing.
    Please help me.

    Not quite sure of your definition of a flat file, but a .xls files is a Microsoft Excel workbook, which is saved in a proprietary binary format, so there's certainly nothing 'flat' about it.  Of course, there are odbc and suchlike drivers for treating Excel workbooks as data sources, but you need to ensure when you query them that you know the details of the workbook.
    In each workbook, each spreadsheet has a name (as defined on it's tab at the bottom).  That is taken to be the name of the 'table' that you use when you query it with SQL.
    On each spreadsheet, row 1 of that sheet should denote the column names of the 'table'
    All subsequent rows on the spreadsheet are the data that will be returned from querying it.
    Typically, the data on the sheets should be fairly straightforward, in order to query it.  Some excel functionality may prevent it being queried properly.

  • Connection to Excel using JDBC

    Hi
    I developed a program to send userid to excel sheet using jdbc...
    While i opened excel sheet and try to send data through jdbc it works great ...
    But the problem is while i closed the excel sheet and try to send data to excel sheet, it spells success.
    But the data i entered is not in that excel sheet ...
    What to do .???
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class InsertExcel
    static JFrame frame;
    static JPanel panel;
    static JTextField textuserid;
    static JTextField textfirstname;
    static JTextField textlastname;
    static JButton submit;
    static JButton exit;
    public static void main(String args[])
    frame = new JFrame("Inserting to excel sheet");;
    panel = new JPanel();
    JLabel labeluserid = new JLabel("User id ");
    JLabel labelfirstname = new JLabel("First Name");
    JLabel labellastname = new JLabel("Last Name");
    textuserid = new JTextField(20);
    textfirstname = new JTextField(20);
    textlastname = new JTextField(20);
    submit = new JButton("Submit to Excel sheet");
    exit = new JButton("Exit");
    panel.add(labeluserid);
    panel.add(textuserid);
    panel.add(labelfirstname);
    panel.add(textfirstname);
    panel.add(labellastname);
    panel.add(textlastname);
    panel.add(submit);
    panel.add(exit);
    frame.getContentPane().add(panel);
    frame.setSize(1024,100);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(3);
    submit.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
         try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:Excel Files","","");
              PreparedStatement stat2 = con.prepareStatement("insert into
    [Book1$](USERID,FIRST_NAME,LAST_NAME) values (?,?,?)");
              stat2.setString(1,textuserid.getText());
              stat2.setString(2,textfirstname.getText());
              stat2.setString(3,textlastname.getText());
              stat2.executeUpdate();
              JOptionPane.showMessageDialog(frame,new String("Successfully entered to excel sheet !!!"));
         catch(Exception e1)
              JOptionPane.showMessageDialog(frame,new String("Error while inserting to excel sheet !!! \n" +
    e1));
    exit.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ex)
         System.exit(0);
    }

    I think this thread has been cross-posted

  • Problems connecting to Internet using Airport - can anyone help ?

    I'm using a MacBook running OSX 10.4.11, trying to connect to internet using Airport. I connected OK first time, but after powering off the Mac, each time I now try to connect again, the Mac can't find the network. Network Diagnostics can't fix it either. I use a Linksys wireless router, connected to an ADSL modem. I use PPPoE. I live in Borneo, and the line connection is not great, occasionally the phone line drops out and then modem reconnects itself, I wonder whether this is causing some sort of problem with IP settings. The only way I can connect wirelessly is to start the Mac, reboot the modem, then the router, and plough through Network Diagnostics. A real pain. Help much appreciated.

    I have a Linksys Wireless-G (model WRT54GS). This is working ok because I have two other wireless devices (internet radio and iPod touch) which connect fine. Firmware is up to date. I've done a bit more troubleshooting, and the the problem is connected with the phone line, which drops out all too regularly. Each time the phone line drops out, the Mac is unable to connect to the network wirelessly. After going through Network diagnostics, and rebooting the modem+router, it comes with a message saying "Network changes detected", and then I can reconnect OK. The funny thing is, the IPod touch can always reconnect no problem, even if the line has dropped out since the last login. Given that I've got a crappy phone line conection, is this normal or is there something wrong with my Mac settings ?

Maybe you are looking for

  • Problems with creating badi implementation for virtual key figures

    Hi, I'm running BI 7.0 (unicode). I have been trying to follow this blog to calculate the virtual keyfigure in my infoset - Using Virtual Key Figure and Characteris in an InfoSet My infoset includes 1 infocube, and 3 master data infoobjects. I have c

  • Stored procedure Performance issue in SQLserver 2005

    Hi All, i am inserting the data to Database by using of Stored procedure in target DB. My source structure and target structures are looking below I have the source structure having lot of rows and look like my structure is below: <?xml version="1.0"

  • ITunes Match Not Uploading

    iTunes match suddenly quit uploading music to the cloud.  It goes through all the other steps but when it comes to uploading it fails.  The songs are reading error beside them and I tried to refresh iTunes Match but it keeps failing to upload.  Is an

  • HT204053 I have bought my grandchildren an ipad and want to set up separate account for this. Is that possible?

    I was wondering if a separate account can be sep-up in your itunes account as I have reached my limit on downloading ipads and would like to sep-up a new account so my grandchildren can play with their ipad

  • Calling CRM ABAP class from SAP Jco

    Hi, In CRM,  there is a class interface called CL_CRM_DOCUMENTS with static methods. I need to make call to these methods from my Java application that uses JCo. Is it possible to call ABAP methods from JCo? Any help in this regard will be highly app