Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,913 members, 8,004,290 topics. Date: Saturday, 16 November 2024 at 01:15 PM

Have Problem Finding My Database; A Java Guru To Assist - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Have Problem Finding My Database; A Java Guru To Assist (3577 Views)

[RESOLVED] How do I package my database with my application? / [Help Request]How Do I Upload Images Into My Database using Visual Basic? / Do You Need To Be A Math Guru To Be A Good Programmer (2) (3) (4)

(1) (Reply) (Go Down)

Have Problem Finding My Database; A Java Guru To Assist by hymnha(m): 8:20am On Mar 31, 2009
While compiling my little java application developed in netbeans, i had the following problem. Initially i had an error of the sort java.sql.sqlException, No suitable driver. After some serious "troubleshooting", I now shows an error: Database 'ManageSite' not found. Where ManageSite is the name of the database. It shows me jdbc:derby://localhost:1527/ManageSite[root on ROOT]. It shows connected, i can view my tables and create more table.
And i can insert data into the database through the SQL command into the database
Can anyone help me Debug
Here is a portion of the code that links and connects the Database

private static final String URL = "jbdc:derby://localhost:1527/MANAGESITE";
private static final String USERNAME = "root";
private static final String PASSWORD = "nbuser";
private Connection connection = null
private static final String Driver = "org.apache.derby.jdbc.EmbeddedDriver";//i also tried ClientDriver instead of EmbeddedDriver
//my constructor
public ClassName () {
try
{
Class.forName(DRIVER);
connection = Driver.getConnection(URL, USERNAME,PASSWORD);
,
,
,
}
catch (ClassNotFoundException cNFException)
{
,
catch (SQLException sqlException)
{
.
.
.
}
}
Re: Have Problem Finding My Database; A Java Guru To Assist by candylips(m): 10:10am On Mar 31, 2009
Hi are u using deby in embedded mode. If you are try this for the db url "jdbc:deby:managesite"
Re: Have Problem Finding My Database; A Java Guru To Assist by hymnha(m): 10:38am On Mar 31, 2009
i did that but it now gives an error:java.lang.ClassNotFoundException; org.apache.derby.ClientDriver

i changed the line of code that has EmbeddedDriver to ClientDriver and it still gives the same Error. Can u help further pls.

Thanks for your concern
Re: Have Problem Finding My Database; A Java Guru To Assist by candylips(m): 11:21am On Mar 31, 2009
make sure derbyclient.jar is in ur classpath. This contains the jdbc driver that you will require
Re: Have Problem Finding My Database; A Java Guru To Assist by hymnha(m): 11:50pm On Mar 31, 2009
Thanks a lot.
The little challenge i now have is that while trying to input data into the database through the form, the app now generates an SQL Error inidcating.
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "VALUE" at line 1, column 59.

The code excerpt for entering data into database table is shown below.

//constructor
public ClassName(){
try
{
Class.forName(DRIVER);
connection = DriverManager.getConnection(URL,USERNAME,PASSWORD)
insertAnotherEntry = connection.prepareStatement("INSERT INTO TABLE" +"(FirstCol, SecondCol, ThirdCol, FourthCol)" + "VALUES (?,?,?,?)"wink;
//insertAnother entry is of type PreparedStatement
//connection of type Connection
}
catch (, )


Pls help me further. i have no idea what the problem is God bless you
Re: Have Problem Finding My Database; A Java Guru To Assist by candylips(m): 9:46am On Apr 01, 2009
i noticed that u don't have spaces before values and the column list.

INSERT INTO TABLE " +"(FirstCol, SecondCol, ThirdCol, FourthCol)" + "  VALUES (?,?,?,?)"wink;

if that doesn't work post the stacktrace of the exception u are getting
Re: Have Problem Finding My Database; A Java Guru To Assist by hymnha(m): 3:49pm On Apr 01, 2009
i tried it but it did not still work. The stack trace is below

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "VALUE" at line 1, column 59.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
at ManageSite.<init>(ManageSite.java:29)
at Add_New_Info.jButton1ActionPerformed(Add_New_Info.java:142)
at Add_New_Info.access$100(Add_New_Info.java:16)
at Add_New_Info$2.actionPerformed(Add_New_Info.java:63)
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:3260)
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)
Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered "VALUE" at line 1, column 59.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
, 30 more
Re: Have Problem Finding My Database; A Java Guru To Assist by candylips(m): 4:57pm On Apr 01, 2009
You might need to post all your code for me to see how u are using the prepared statement. looks like an sql syntax error

do u have something like these

insertAnotherEntry.setString(1,"blah"wink
insertAnotherEntry.executeUpdate()

are the names of the columns in quotes?

Also you might want to change this INSERT INTO TABLE " +"(FirstCol, SecondCol, ThirdCol, FourthCol)" + " VALUES (?,?,?,?)"wink;

to this "INSERT INTO TABLE VALUES (?,?,?,?)"wink; if you will be inserting to all the columns in your table
Re: Have Problem Finding My Database; A Java Guru To Assist by hymnha(m): 10:55pm On Apr 01, 2009
This addEntry() method is in the class that manages database connection called ManageSite

public int addEntry(String sname, String smail, String pword, String descriptn)
{
int result = 0;
try
{
insertAnotherEntry.setString(1, sname);
insertAnotherEntry.setString(2, smail);
insertAnotherEntry.setString(3, pword);
insertAnotherEntry.setString(4, descriptn);

result = insertAnotherEntry.executeUpdate();
return result;
}
catch (SQLException sqlException)
{
sqlException.printStackTrace();
close();
}
return 0;//return zero if problem occurs
}

This method is called under the submit button as shown below. method close in catch block of method addentry() is meant to close database connection.



private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
ManageSite manageSite = new ManageSite();
int result = manageSite.addEntry(siteNameTextField.getText(), siteMailTextField.getText(), passwordTextField.getText(), descriptionTextArea.getText());
if (result == 1)
JOptionPane.showMessageDialog(this,"Entry Added!", "Entry Added", JOptionPane.PLAIN_MESSAGE );
else
JOptionPane.showMessageDialog(this,"Entry not Added!","Error", JOptionPane.PLAIN_MESSAGE);
}
Thanks for your care. I'm most grateful.
Re: Have Problem Finding My Database; A Java Guru To Assist by hymnha(m): 12:06pm On Apr 04, 2009
Let somebody help me PLs
Re: Have Problem Finding My Database; A Java Guru To Assist by Afam(m): 1:40pm On Nov 13, 2009
If you were running PHP I am sure someone would have provided the answer to the problem as soon as you posted it.

Another reason to embrace a language that has great support from across the world.

I wish I could help.
Re: Have Problem Finding My Database; A Java Guru To Assist by logica(m): 2:58pm On Nov 13, 2009
Must be a post for the April Fool of 2009. Why will anybody respond with any seriousness to this dead thread?

In any case, I MOSTLY ignore posts like these because I believe a programmer should be self-taught. Such trivial issues are stuff you should figure out yourself (either by tasking your brain or doing a search on the Net).
Re: Have Problem Finding My Database; A Java Guru To Assist by candylips(m): 3:22pm On Nov 13, 2009
hymnha:

Let somebody help me PLs

Did you try my last suggestion

Your code looks fine but i think there is a problem with your SQL syntax from the stacktrace you posted.

Also make sure that the types of the columns you are inserting stuff into matches the java types you are tryin to had to it
Re: Have Problem Finding My Database; A Java Guru To Assist by logica(m): 3:33pm On Nov 13, 2009
candylips:

It's obvious the guy did not correct the code (did not leave a space between the closing bracket and 'VALUES' keyword, which you fixed, but he apparently missed the correction). Besides, it's been how many months now? 9 months?
Re: Have Problem Finding My Database; A Java Guru To Assist by Nobody: 11:55pm On Nov 20, 2009
hymnha:

i tried it but it did not still work. The stack trace is below

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "VALUE" at line 1, column 59.
        at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
        at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
        at ManageSite.<init>(ManageSite.java:29)
        at Add_New_Info.jButton1ActionPerformed(Add_New_Info.java:142)
        at Add_New_Info.access$100(Add_New_Info.java:16)
        at Add_New_Info$2.actionPerformed(Add_New_Info.java:63)
        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:3260)
        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)
Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered "VALUE" at line 1, column 59.
        at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
        at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
        at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
        at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
        at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
        at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
        at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
        at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
        at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
        at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
        at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
        ,  30 more


close to a hundred line, when will java stop frustrating you guys?
Re: Have Problem Finding My Database; A Java Guru To Assist by kencas: 9:20am On Nov 30, 2009
Ur code is correct. from the exception statement,Check the correct name of the columns,and the table name, and also check whether the datatype conforms to the type assigned to the preparedstatement

(1) (Reply)

Friendzone / Let's Learn Python-striktly Noobed!! / What's new in PHP 5 and PHP 6

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.