Results 1 to 2 of 2
Thread: Connecting to a database table
- 05-19-2010, 07:56 AM #1
Member
- Join Date
- May 2010
- Posts
- 7
- Rep Power
- 0
Connecting to a database table
I was successful writing down the java code that connects to my JavaDB.(Am using NetBeans IDE).I want to retrieve content from my table called workers(Under the APP' SCHEMA) but that isnt possible.When I run my code,the following happens.
'Schema 'KMUGALAASI' doesnt exit'.
BUILD SUCCESSFUL.
Can anyone tell mi what that means and how can I solve that problem? So that I can retrieve contents FROM MY TABLE(Workers with columns-ID,First_Name,Last_Name and Job_Title).Have a look at my code.
package database_console;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class DBConnect {
public static void main(String[] args) {
try {
String host = "jdbc:derby://localhost:1527/Employees";
String uName = "kmugalaasi";
String uPass = "GETAFE";
Connection con = DriverManager.getConnection(host,uName,uPass);
Statement stmt = con.createStatement();
String SQL = "SELECT * FROM Workers";
ResultSet rs = stmt.executeQuery(SQL);
while (rs.next()) {
int id_col = rs.getInt("ID");
String first_name = rs.getString("First_Name");
String last_name = rs.getString("Last_Name");
String job = rs.getString("Job_Title");
String p = id_col + " " + first_name + " " + last_name + " " + job;
System.out.println(p);
}
}
catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
- 05-19-2010, 10:33 AM #2
No java related error.close the connection object and statement object once done with db opertions.
This is more related to derby database connectivity.Please go thru the below tutorial.
Establishing a Connection (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics)Ramya:cool:
Similar Threads
-
connecting to a foxpro table
By lduren in forum New To JavaReplies: 1Last Post: 05-02-2010, 08:39 AM -
connecting to a database
By mxb7642 in forum JDBCReplies: 5Last Post: 09-08-2009, 08:39 AM -
connecting to a database
By kswiss in forum NetBeansReplies: 4Last Post: 06-25-2009, 06:22 PM -
Connecting JSP with database
By ramachandran in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 05-13-2009, 06:15 AM -
Connecting to a database
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2008, 02:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks