Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.jar
*.swp
*.bak
*.ent
*.versionsBackup
dependency-reduced-pom.xml
asm-9.7.jar
Expand Down
21 changes: 15 additions & 6 deletions Configure.pl
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ sub search_maven_artifact {
}
print "Select number [0-" . $#docs . "]: ";
my $choice = <STDIN>;
unless (defined $choice) {
warn "No input received (not running interactively?). Defaulting to [0].\n";
$choice = 0;
}
chomp $choice;
$choice = 0 unless $choice =~ /^\d+$/ && $choice <= $#docs;
return $docs[$choice]{id};
}

Expand Down Expand Up @@ -510,12 +515,16 @@ sub score_jdbc_relevance {
my $score = 0;

# Higher score for JDBC indicators
$score += 5 if $doc->{g} =~ /jdbc/i;
$score += 5 if $doc->{a} =~ /jdbc/i;
$score += 3 if $doc->{g} =~ /database|mysql|postgresql|oracle|sqlserver/i;
$score += 3 if $doc->{a} =~ /database|mysql|postgresql|oracle|sqlserver/i;
$score += 2 if $doc->{latestVersion} =~ /jdbc/i;
$score += 4 if $doc->{c} =~ /Driver$/;
my $g = $doc->{g} // '';
my $a = $doc->{a} // '';
my $v = $doc->{latestVersion} // '';
my $c = $doc->{c} // '';
$score += 5 if $g =~ /jdbc/i;
$score += 5 if $a =~ /jdbc/i;
$score += 3 if $g =~ /database|mysql|postgresql|oracle|sqlserver/i;
$score += 3 if $a =~ /database|mysql|postgresql|oracle|sqlserver/i;
$score += 2 if $v =~ /jdbc/i;
$score += 4 if $c =~ /Driver$/;

# Boost score based on download count
$score += log($doc->{downloadCount} || 1);
Expand Down
28 changes: 17 additions & 11 deletions docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ sudo dpkg -r perlonjava
```bash
./jperl -E 'print "Hello World"'
./jperl myscript.pl
CLASSPATH="jdbc-drivers/h2-2.2.224.jar" ./jperl myscript.pl
```

**Windows:**
```bash
jperl -E "print 'Hello World'"
jperl myscript.pl
set CLASSPATH=jdbc-drivers\h2-2.2.224.jar
jperl myscript.pl
```

### Common Options
Expand All @@ -132,18 +129,23 @@ jperl myscript.pl

1. Using Configure.pl:
```bash
./Configure.pl --search mysql-connector-java
./jperl Configure.pl --search mysql-connector-java
```

2. Using Java classpath (shown in platform-specific examples above)

### Database Connection Example

SQLite is bundled with PerlOnJava — no additional installation needed:

```perl
use DBI;
my $dbh = DBI->connect("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
$dbh->do("CREATE TABLE test (id INT, name VARCHAR(50))");
my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:", "", "");
$dbh->do("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
```

For other databases, add JDBC drivers via CLASSPATH or Configure.pl (see below).

See [Database Access Guide](../guides/database-access.md) for detailed connection examples and supported databases.

## Build Notes
Expand All @@ -165,33 +167,37 @@ See [Database Access Guide](../guides/database-access.md) for detailed connectio

The `Configure.pl` script manages configuration settings and dependencies for PerlOnJava.

> **Tip:** Using `./jperl` to run Configure.pl is recommended because it includes
> built-in HTTPS support. System Perl may require additional modules
> (`IO::Socket::SSL`, `Net::SSLeay`) for the Maven Central search to work.

### Common Tasks

**View current configuration:**
```bash
./Configure.pl
./jperl Configure.pl
```

**Add JDBC driver (search):**
```bash
./Configure.pl --search mysql
./jperl Configure.pl --search mysql
make # Rebuild to include driver
```

**Add JDBC driver (direct):**
```bash
./Configure.pl --direct com.h2database:h2:2.2.224
./jperl Configure.pl --direct com.mysql:mysql-connector-j:8.2.0
make # Rebuild to include driver
```

**Update configuration:**
```bash
./Configure.pl -D perlVersion=v5.42.0
./jperl Configure.pl -D perlVersion=v5.42.0
```

**Upgrade all dependencies:**
```bash
./Configure.pl --upgrade
./jperl Configure.pl --upgrade
```

### Available Options
Expand Down
35 changes: 18 additions & 17 deletions docs/guides/database-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ This guide explains how to use databases with PerlOnJava through the DBI module

## Quick Start

SQLite is bundled with PerlOnJava — no additional installation needed:

```perl
use DBI;

my $dbh = DBI->connect("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
$dbh->do("CREATE TABLE users (id INT, name VARCHAR(50))");
my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:", "", "");
$dbh->do("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");
```

## Adding JDBC Drivers

JDBC Database drivers can be added in two ways:
SQLite works out of the box. For other databases, JDBC drivers can be added in two ways:

1. Using Configure.pl:
- The Configure script updates the build configuration to install the JDBC database drivers in the PerlOnJava jar file
Expand All @@ -22,8 +24,8 @@ JDBC Database drivers can be added in two ways:

Examples:
```bash
./Configure.pl --search mysql-connector-java
./Configure.pl --search aws-mysql-jdbc
./jperl Configure.pl --search mysql-connector-java
./jperl Configure.pl --search aws-mysql-jdbc
```

Then build with the drivers included:
Expand All @@ -39,29 +41,33 @@ gradle clean build

Unix/Linux/Mac:
```bash
CLASSPATH="jdbc-drivers/h2-2.2.224.jar" ./jperl myscript.pl
CLASSPATH="jdbc-drivers/mysql-connector-j-8.2.0.jar" ./jperl myscript.pl
```

Windows:
```bash
set CLASSPATH=jdbc-drivers\h2-2.2.224.jar
set CLASSPATH=jdbc-drivers\mysql-connector-j-8.2.0.jar
jperl myscript.pl
```

Calling java directly with the classpath is also possible:
```bash
java --enable-native-access=ALL-UNNAMED -cp "jdbc-drivers/h2-2.2.224.jar:target/perlonjava-5.42.0.jar" org.perlonjava.app.cli.Main myscript.pl
java --enable-native-access=ALL-UNNAMED -cp "jdbc-drivers/mysql-connector-j-8.2.0.jar:target/perlonjava-5.42.0.jar" org.perlonjava.app.cli.Main myscript.pl
```

## Database Connection Examples

### H2 Database
### SQLite (bundled)
```perl
# In-memory database
my $dbh = DBI->connect("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
# In-memory database (Perl DBI DSN format)
my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:", "", "");

# File-based database
my $dbh = DBI->connect("jdbc:h2:file:/path/to/database");
my $dbh = DBI->connect("dbi:SQLite:dbname=/path/to/database.db", "", "");

# JDBC URL format also works
my $dbh = DBI->connect("jdbc:sqlite::memory:");
my $dbh = DBI->connect("jdbc:sqlite:/path/to/database.db");
```

### MySQL
Expand All @@ -82,11 +88,6 @@ my $dbh = DBI->connect(
);
```

### SQLite
```perl
my $dbh = DBI->connect("jdbc:sqlite:/path/to/database.db");
```

### BigQuery
```perl
my $dbh = DBI->connect(
Expand Down
Loading
Loading