• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing connection variable from another class and perform query

 
Preeto Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
I am beginner in java.
I want to access variable JDBC database connection variable conn from class test.java to Test2.java in jdk 1.8 . Both classes are in Tool package. Database name is UOHStudents and table is usertest
My question is : can I access the connection variable by making object in another class? If yes the please check the code where I am doing mistake?

test.java


Test2.java

 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you able to compile Test2.java ?
If yes what is the output when you execute it?
If no what is the compilation error?
 
Preeto Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while compiling 2 errors are coming ... I couldn't find such type error of semicolon(;).

C:\Users\PREETI\Desktop\JAVA\ABBDTool\src\Tool>javac Test2.java
Test2.java:26: error: illegal start of expression
    public  Test2()    

    ^
Test2.java:26: error: ';' expected
    public  Test2()
                   ^

2 errors

 
Henry Wong
author
Marshal
Pie
Posts: 22095
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Defining a method, directly inside another method, is not valid syntax in Java.

Henry
 
Preeto Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@henry

Can you please help me in searching the same in code...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preeto Singh wrote:@henry

Can you please help me in searching the same in code...

He's saying this can't be in your main method:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic